Last active
November 2, 2020 20:06
-
-
Save bugkiller78/c43729a369cb4aefd421fa329203450b to your computer and use it in GitHub Desktop.
DN4.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import json | |
import random | |
secret = random.randint(1,30) | |
attempts = 0 | |
current_time = datetime.datetime.now() | |
print(current_time) | |
with open('score_list.txt' , 'r') as score_file: | |
score_list = json.loads(score_file.read()) | |
ime = str.upper(input('Please enter your name: ')) | |
while True: | |
guess = int(input(ime + ' Please guess your secret number between 1 and 30: ')) | |
attempts += 1 | |
if guess > 30 or guess < 1: | |
print('Guessed number is invalid, please insert avalid number!') | |
elif guess == secret: | |
score_list.append({"ime igralca": ime, "secret_number": secret, "attempts":str(attempts), "date": str(datetime.datetime.now())}) | |
with open('score_list.txt', 'w') as score_file: | |
score_file.write(json.dumps(score_list)) # obvezno v datoteki score_list.txt začeti z oklepaji [] | |
print('Congratulations, you guessed the right number ' + str(secret) + ' in ' + str(attempts) + ' attempts!') | |
break | |
elif guess < secret: | |
print('Sorry, wrong number, please try with something bigger!') | |
print('') | |
elif guess > secret: | |
print('Sorry, wrong number, please try with something smaller!') | |
print('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment