3.6
Hack 1
Create a simple conditional statement.
# Declaring two boolean values
is_raining = False
is_bored = True
# Compares one value to the opposite of the other value
if is_bored and not is_raining:
print("Go play outside!")
else:
print("idk what to tell you man")
Go play outside!
Hack 2
Create a piece of code that compares two statements and checks if they are equal to each other.
# Declaring two string values
friend_one = "Billy"
friend_two = "Bobby"
# Declaring two integer values
friend_one_length = len(friend_one)
friend_two_length = len(friend_two)
# Compares the values with each other
if friend_one == friend_two:
print("Wow the friends have the same name!")
elif friend_one_length == friend_two_length:
print("Wow the friends' names have the same amount of letters!")
else:
print("The friends have completely different names.")
Wow the friends' names have the same amount of letters!
Hack 3
Create a simple program that classifies an individual as a “Child,” “Teenager,” or “Adult” based on their age input.
age = int(input())
if age < 13:
print("You are a child")
elif age < 18:
print("You are a teenager")
else:
print("You are an adult")
You are a child
Hack 4
Create a counter function that takes input.
# Defining a function that takes an integer parameter, `n`
def counter(n):
# Loop `n` times
for i in range(n):
# Take input
inp = input("Type the number " + str(i))
# Continue if the number is correct, break if it isn't
if int(inp) == i:
continue
else:
print("Come on man...")
break
# Call the function with value of user's input
counter(int(input("Enter any number! ")))
Come on man...