Let me know if you edit this script yourself to make a better version! This was something I coded up quickly so I'm sure it can be improved. There's a lot more examples of simple python games that can be found on GitHub. Here's a repo you might find interesting:
github.com/grantjenks/free-python-games
Hey Everyone! In this one we'll go over quite a few small topics:
Python Game logic
Python progressive difficulty
While Loops
If statements
How to use Python Random
How to use Python functools
How to use python sleep
breaking/continuing while loops
Time module: docs.python.org/3.7/library/time.html
Random Module: docs.python.org/3/library/random.html
Functools: docs.python.org/3/library/functools.html
Math Module: docs.python.org/3/library/math.html
Thanks so much for the support! You guys are awesome - here's your daily reminder, haha. 4,370 subscribers at the time of writing, how incredible. Thanks so much for all the kind words across all the videos, I read and try to respond to every comment I can.
*****************************************************************
Full code from the video:
import time
import functools
import operator
import random
import math
print('Number Time quiz!')
time.sleep(2)
print('Answer the multiplcation problems before time runs out!')
time.sleep(3)
print('Ready? Go!')
start_time = time.time()
score = 0
Game Logic
while True:
difficulty_setting = 2
difficulty_progression = math.floor(score/10)
overall_difficulty = difficulty_setting + difficulty_progression
numbers_list = []
for x in range(overall_difficulty):
value = random.randint(1,9)
numbers_list.append(value)
answer = functools.reduce(operator.mul, numbers_list, 1)
print('Multiple these numbers', numbers_list)
guess = int(input())
if guess == answer:
score = score + (1 * overall_difficulty)
continue
else:
print('Game over! The answer was', answer)
elapsed_time = time.time() - start_time
print('Your score was', score, 'In only', elapsed_time)
break
github.com/Derrick-Sherrill/DerrickSherrill.com/bl…
*****************************************************************
Code from this tutorial and all my others can be found on my GitHub:
github.com/Derrick-Sherrill/DerrickSherrill.com
Check out my website:
www.derricksherrill.com/
If you liked the video - please hit the like button. It means more than you know. Thanks for watching and thank you for all your support!!
Always looking for suggestions on what video to make next -- leave me a comment with your project! Happy Coding!
コメント