Merge branch 'main' of https://git.verhaar.xyz/marcv/Python-Course
This commit is contained in:
31
Defining_funtions.py
Normal file
31
Defining_funtions.py
Normal file
@@ -0,0 +1,31 @@
|
||||
def hello(name):
|
||||
print(f'Hello {name}! How are you?')
|
||||
|
||||
username = input('What is your name stranger?\n>')
|
||||
hello(username)
|
||||
|
||||
# Another example using functions and return code:
|
||||
|
||||
import random
|
||||
|
||||
# Defining the function:
|
||||
def get_answer(answer):
|
||||
if answer <10:
|
||||
return "The answer is smaller than 10"
|
||||
elif answer == 10:
|
||||
return "The answer is 10."
|
||||
else:
|
||||
return 'The answer is greater than 10'
|
||||
|
||||
# Generating a random number, using that random number to define a variable by using it as an argument in the funtion,
|
||||
# and printing the result:
|
||||
random_number = random.randint(1, 20)
|
||||
result = get_answer(random_number)
|
||||
print(result)
|
||||
|
||||
# The 3 lines above can be rewritten to a single line:
|
||||
print(get_answer(random.randint(1, 20)))
|
||||
|
||||
# And the check to see if the code is working as it should:
|
||||
print(f"(It is {random_number})")
|
||||
|
||||
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)
|
||||
3
future_projects.md
Normal file
3
future_projects.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Some ideas for future challenges learning ptyhon:
|
||||
|
||||
- black jack
|
||||
11
playground.py
Normal file
11
playground.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import random
|
||||
for i in range(100): # Perform 100 coin flips.
|
||||
if random.randint(0, 1) == 0:
|
||||
print('H', end=' ')
|
||||
else:
|
||||
print('T', end=' ')
|
||||
print()
|
||||
|
||||
|
||||
# print('Deze print eindigt met een spatie', end=" ")
|
||||
# print("Dit staat er naast")
|
||||
@@ -1,6 +1,6 @@
|
||||
#############################################
|
||||
# #
|
||||
# Work in progress!! #
|
||||
# Done! #
|
||||
# #
|
||||
#############################################
|
||||
|
||||
@@ -137,4 +137,4 @@ wins: {wins}, losses: {losses}, ties: {ties}''')
|
||||
wins: {wins}, losses: {losses}, ties: {ties}''')
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user