Add functions and return codes
This commit is contained in:
5
Defining_funtions.py
Normal file
5
Defining_funtions.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
def hello(name):
|
||||||
|
print(f'Hello {name}! How are you?')
|
||||||
|
|
||||||
|
username = input('What is your name stranger?\n>')
|
||||||
|
hello(username)
|
||||||
31
Return_codes_Magic_8_ball.py
Normal file
31
Return_codes_Magic_8_ball.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
|
# This input only makes the user think the program reacts to his question!
|
||||||
|
# In reality it doesn't do anything!
|
||||||
|
|
||||||
|
input("Ask your question. Be sure it can be answered with a YES or NO!\n>")
|
||||||
|
|
||||||
|
# Define function and based on the evaluation define return code:
|
||||||
|
|
||||||
|
def get_answer(random_number):
|
||||||
|
if random_number == 1:
|
||||||
|
return 'It is certain!'
|
||||||
|
elif random_number == 2:
|
||||||
|
return 'It is decidedly so.'
|
||||||
|
elif random_number == 3:
|
||||||
|
return 'Yes'
|
||||||
|
elif random_number == 4:
|
||||||
|
return "Doubtful"
|
||||||
|
elif random_number == 5:
|
||||||
|
return 'Not likely'
|
||||||
|
elif random_number == 6:
|
||||||
|
return 'Mhhh, not sure about that one'
|
||||||
|
elif random_number == 7:
|
||||||
|
return "Nope, afraid not"
|
||||||
|
else:
|
||||||
|
return "No way in hell"
|
||||||
|
|
||||||
|
|
||||||
|
r = random.randint(1,8)
|
||||||
|
fortune = get_answer(r)
|
||||||
|
print(fortune)
|
||||||
@@ -1,40 +1,7 @@
|
|||||||
# def hello():
|
def hello(name):
|
||||||
# # Print 3 greetings:
|
print(f'Hello {name}! How are you?')
|
||||||
# print("Good morning!")
|
|
||||||
# print("Good afternoon!")
|
|
||||||
# print("Good night!")
|
|
||||||
|
|
||||||
# hello()
|
|
||||||
# hello()
|
|
||||||
# print('One more time')
|
|
||||||
# hello()
|
|
||||||
|
|
||||||
# def say_hello(name):
|
|
||||||
# print(f'Hello {name}')
|
|
||||||
|
|
||||||
# say_hello('Marc')
|
|
||||||
|
|
||||||
import random
|
|
||||||
|
|
||||||
def get_answer(random_number):
|
|
||||||
if random_number == 1:
|
|
||||||
return 'It is certain!'
|
|
||||||
elif random_number == 2:
|
|
||||||
return 'It is decidedly so.'
|
|
||||||
elif random_number == 3:
|
|
||||||
return 'Yes'
|
|
||||||
elif random_number == 4:
|
|
||||||
return "Doubtful"
|
|
||||||
elif random_number ==5:
|
|
||||||
return 'Not likely'
|
|
||||||
else:
|
|
||||||
return "No way in hell"
|
|
||||||
|
|
||||||
print("Ask a yes or no question:\n>")
|
|
||||||
input()
|
|
||||||
r = random.randint(1,5)
|
|
||||||
fortune = get_answer(r)
|
|
||||||
print(fortune)
|
|
||||||
|
|
||||||
|
username = input('What is your name stranger?\n>')
|
||||||
|
hello(username)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user