Functions - no parameters
def main():
done = False
while not done:
print("Menu")
print("D - Do Now")
print("Q - Quit")
choice = input("Choice: ")
if choice == "D":
print("Do Now")
name = input("What's your name")
print(name,"welcome back!")
elif choice == "Q":
print("Exiting Game!")
done = True
main()Example 1
Create a function named e1.
Using a for loop, print your name 5 times.
Call the function e1 within the main function.
Example 2
Create a function named e2.
Using a for loop, print numbers from 0 to 4.
Call the function e2 within the main function.
Example 3
Create a function named e3.
Using a for loop, create a table to show the numbers -5 to 5 and their squares. Create a header
print("Number\tSquared")
Call the function e3 within the main function.
Example 4
Create a function named e4.
Write Python code that converts Celsius to Fahrenheit for the following values of Celsius: 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100.
Use the following formula:
F=9/5C+32
Create a header:
print("Celsius\tFahrenheit")
Call the function e4 within the main function.
Last updated
Was this helpful?