Hard-coding a value is when you set the value directly into the code. For example, age=2 below.
age = 2
ten_times_age=10*age
print ("This is 10x your age:")
print(ten_times_age)
Result:
This is 10x your age:
20
To provide more flexibility to your programming, you can allow the user to input a value using the input() function, as in the Trinket below!
1. Update the code you wrote from “Simple Coding Example” in 1.5 to calculate and display your age in both years and days using user input. The general syntax for user input is x = input('Ask a question here'), then the variable x is assigned to that user input. Test it out!
2. Write a program that asks the user to input their favorite color and then print it out by filling in the blanks.
Tip: If you do not know an answer try it in the scratch space above!