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?