Skip to main content

Chapter 3a - Inputs

๐Ÿ‘€

Inputโ€‹

๐Ÿ‘€

test = input()
print(test)
๐Ÿงช Try the code out~!

Prompting user input withouth print()โ€‹

inputEnteredByUser = input("write something")
print(inputEnteredByUser)
๐Ÿงช Try the code out~!

Review

Play with this:


๐Ÿ›  Fix the following code so that you can replicate the behavior from the program above ๐Ÿ‘†

  • Notice how the program below ๐Ÿ‘‡ doesn't ask for the user to write anything on the terminal (the left box under Result)
  • And just straight prints whatever is hard-coded inside of the variable name
Time to work on our Class Project!

Click here to go to our Amongus project 3a You only need to complete this for this class. But if you would like to, feel free to peek into the topics below!

Implementation Exampleโ€‹

Prompting a triangle color.โ€‹

# 3-input-d
import turtle

# Ask user to enter the pen color
color = input("Enter a color for turtle's pen color")

# Set the turtle's pencolor
turtle.pencolor(color)

turtle.forward(100)
turtle.left(120)
turtle.forward(100)
turtle.left(120)
turtle.forward(100)
turtle.left(120)
๐Ÿงช Try the code out~!

Robot Clerk: User Inputs and your bakery calculatorโ€‹

๐Ÿ‘€

# this program generates a bill based on the items shopped
print("The following items are availabe at Bake Bar:")
print("Shortcakes at $1.5 per cake")
print("Macaron at $1 per piece")
print("Chocochip cookies at $1 per cookie")
print("") # leave a line before printing other info

shortcake = int(input("Enter the number of shortcakes you want "))
macaron = int(input("Enter the number of macarons you want "))

costCake = 1.5 * shortcake # calculate the money spent on shortcake
costMacaron = 1 * macaron # calculate the money spent on macarons
totalCost = costCake + costMacaron # calculate the total money spent on all 3 items

print("Bill amount for your shopping is " + str(totalCost))

๐Ÿงช Try the code out~!

Exerciseโ€‹

Madlibโ€‹

๐Ÿ‘€

๐Ÿ“Exercise: Complete the following Program
  • Adverbs examples: Above, Away, Back, Behind, Fairly, always
  • Adjective examples: Cruel, Charming, Fantastic
  • Noun examples: Goat, Chicken, Lemon
  • Verb examples: Run, Hide, Eat

Expected Result:

โœ You can solve the problem here using Trinket
- You can see that the code here doesn't print the adjective, noun or verb, or is asking the prompt for it. Please complete the program so it does so.
Instructor Notes