RESOURCES: Class slides: https://docs.google.com/presentation/d/1zIPSvXFg7eEVjguovCNHKpuojvqCq6eA5tjJpfGnSKc/edit?usp=sharing
Coding platform: replit.com
Discord: https://discord.gg/FKKAcmrr
HOMEWORK:
Give 3 examples of each data type (2 examples for Booleans).
Take user input and tell an interactive story using f-strings and concatenation of variables and print statements.
Example of a starting point:
username = input(“What is your name?”)
print(username + “, you know my name, not my story”)
Post your answers as a comment! Solutions will be posted later.
Feel free to email shravyassathish@gmail.com (mentor) or kingericwu@gmail.com (TA) if you're stuck or have questions! See you next class :)
#strings: "food", "cat", "bell pepper" #integers: 3, 4, 12 #floats: 0.5, 0.23, 4.56 #booleans: true, false username = input("What is your name? ") print(username + ", you know my name, not my story.") print("one day, as I was walking to the store, I found that there was a ravine formed by a recent earthquake. There were three bridges spanning the chasm. A sign said to use the first bridge, but the bridges were not labeled. Should I choose the left, middle or right bridge?") bridgeChoice = input("Which bridge did I choose? ") print("I chose the "+bridgeChoice+" bridge. Thankfully, it was safe and I soon got to the store. At the store, I bought many things.") item = input("one thing I bought was a ") adj = input("however, it was a "+item+" that looked ") print("after that, I went home with my "+adj+" "+item+".")
ReplyForward
Hi everyone, sorry I wasn't there for the 2 classes, I was out in Florida. I'll be posting homework solutions in the comments before the next class. If you need other examples you can also look at solutions from other students.
Part 1
Strings: "Hello", 'Hello', '12345'
Integers: 123, 456, 90
Floats: 1.1, 2.0, -3.4
Booleans: True and False
Part 2
name = input("Hello, what is your name? ")
hobbies = input("What hobbies do you have? ")
print(f"Hello {name}, welcome to Intro to Python!")
print("I hear you like to do", hobbies)
print("Get ready to add coding to that list if it wasn't already there")
print("See you soon", name)
Two/Three Examples for Each Data Type:
a. Strings: Hello, hEllo, heLlo
b. Integers: 3, 1, 4
c. Float: 3.14, 2.71, 9.99
d. Booleans: True, False
Story:
name = input("Hello there, human being. What is your name?: ")
age=input("Nice to meet you," + name + ". How old are you?: ")
if int(age)>=0:
print(f'You are {age} years old.')
color=input("What's your favorite color, " + name + "?: ")
time=input("What time is it?: ")
adjective1=input("Enter any adjective: ")
adjective2=input("Enter a second adjective: ")
noun1=input("Enter any noun: ")
noun2=input("Enter a second noun: ")
print("Okay, here's a random story that will probably not make sense.")
start=input("Are you ready (yes/no): ")
if "yes":
print(f'At {time}, {name} became {adjective1} when they saw {noun1}.')
next=input("Do you want to know what happens next? (Yes/No): ")
if "Yes":
print(f'One second later, {name} turned into a {adjective2} {noun2} and died. Goodbye.')
elif "No":
print("Goodbye.")
else:
print(f'Goodbye, {name}.')
elif "no":
print("Goodbye.")
else:
print("I don't understand.")
else:
print(f'You are not {age} years old. Goodbye.')
Two/Three Examples for Each Data Type:
a. Strings: Hello, hEllo, heLlo
b. Integers: 3, 1, 4
c. Float: 3.14, 2.71, 9.99
d. Booleans: True, False
Story:
name = input("Hello there, human being. What is your name?: ")
age=input("Nice to meet you," + name + ". How old are you?: ")
if int(age)>=0:
print(f'You are {age} years old.')
color=input("What's your favorite color, " + name + "?: ")
time=input("What time is it?: ")
adjective1=input("Enter any adjective: ")
adjective2=input("Enter a second adjective: ")
noun1=input("Enter any noun: ")
noun2=input("Enter a second noun: ")
print("Okay, here's a random story that will probably not make sense.")
start=input("Are you ready (yes/no): ")
if "yes":
print(f'At {time}, {name} became {adjective1} when they saw {noun1}.')
next=input("Do you want to know what happens next? (Yes/No): ")
if "Yes":
print(f'One second later, {name} turned into a {adjective2} {noun2} and died. Goodbye.')
elif "No":
print("Goodbye.")
else:
print(f'Goodbye, {name}.')
elif "no":
print("Goodbye.")
else:
print("I don't understand.")
else:
print(f'You are not {age} years old. Goodbye.')
3 data types=integer (14) boolean (True, False) float (3.5)
username=input("What is your name?")
print("Hello " + username + "!")
print(f"{username} is new to the class.")
age=input("How old are you?")
print("I am ",age)
food=input("What is your favorite food?")
print(f"I like {food} too!")
book=input("What is your favorite book?")
print(f" I do not like {book}. I think it is very boring")
state=input("which state do you live in?")
print(f'I live in {state} too!')
print("bye I have to go")
livingthing = input("What are you?")
print("Once upon a time, there was a", livingthing,".")
characteristic = input("What could you be described as?")
print("This", livingthing, "was very", characteristic, ".")
wordlestarter = input("What is your wordle starting word?")
if len(wordlestarter) == 5:
print("Good Choice!")
goodtrait = input("What is good about you?")
print("You are very", goodtrait, "because you are good at wordle, I'm so proud. ;D")
else:
print("Error")
badtrait = input("What is bad about you?")
print("You are very", badtrait, "because you are bad at wordle, figure it out. >:O")
Was this what we were supposed to do?
user_name = input("What is your name? ")
print("Hello there " + user_name+ ", welcome:)")
fruit = input("What is your favorite fruit? ")
print(f'I love {fruit} too!')
music = input("What type of music genre do you like the most? ")
print(f'Wow! It is cool that you love to listen to {music}. I love it too!')
print("I love to listen to alternative rock music while eating " + fruit)
print(user_name + ", we have so much in common!")
username = input("What is your name? ")
print("Well " + username + ". You may think you know me very well but you haven't heard my crazy story before.")
usertime = input("What time is it? ")
print("It was " + usertime + " when I had witnessed something crazy happen.")
userfriend = input("What is your friend's name? ")
print("I was just strolling in the woods with " + userfriend + " when I heard sirens in the woods. I walked in the woods but there was nothing.")
useranimal = input("What animal is your pet?")
useranimalname = input("What is your pet's name? ")
print(userfriend + " was cold and hungry and wanted to go but I decided to investigate. I saw a shadow that looked like a " + useranimal + " and I was pretty sure it was " + useranimalname)
useranimalscared = input("What animal are you scared of?")
print("If you were there though, you would think it was " + useranimalscared + " and ran away and wet your pants")
usernaturaldisastor = input("What natural disastor happened?")
userfavoritecolor = input("What is your favorite color?")
print("All of a sudden, a " + usernaturaldisastor + " started and I knew I had to get out of there. The funny thing is, I saw a " + userfavoritecolor + " beam of light in the sky and " + useranimalname + " coming out of it. " + userfriend + " wonders if it was you, but hey, we can never know.")
username = input("What is your name? ")
hasSiblingStr = input("Do you have sibling? True or False: ")
hasSibling = eval(hasSiblingStr)
numOfSibling = 0
if hasSibling:
numOfSibling = int(input("How many sibling do you have? "))
Age = input("How old are you? ")
Age = int(Age)
candyName = input("What is your favorite candy? ")
isAteAlready = input("Have you ate one today? yes or no: ")
if isAteAlready == "yes":
ateToday = True
else :
ateToday = False
weight = input("How many lbs do you weight ? ")
'''print(type(weight))'''
w=int(weight)
if ateToday :
verb ="have"
else:
verb = "haven't"
print("----------------We start to analyzing you---------------")
print('Hi '+ username +' How are you doing today?')
print(f"You have {numOfSibling} sibling")
print(f'you are {Age} years old')
if Age<=12:
print("You are a kid")
elif Age <=18:
print("You are a teenager")
elif Age<=45:
print("You are an adult")
elif Age<=80:
print("You are old")
else:
print("You are too too old")
print("Your favorite candy is "+ candyName +" you "+verb+ " eaten candies today")
print("your weight is "+weight)
if w > 90:
print(f'You are overweight. It is never too late to quit {candyName}')
else:
print("your weight is fine. But "+candyName+" are not good for your teeth. Please eat more apples")