i'm a beginner and this is the second program that i have written by myself from scratch, i wrote a basic snake game with PYgame but i didn't do it by myself, so anyway, what do you guys think of this? i want honest opinions, no sugar-coating ! does it have any problems? is there any improvements that can be done?
import random
print "Guess my number!"
print " What's your name?"
user_name = raw_input()
print "Hello %s, i'm thinking of a number between 1 and 20." %(user_name)
def gameloop():
random_number = random.randrange(1,21)
print "Take a guess."
vectory_message = "Well done %s, You beat me!" %(user_name)
defeat_message = "Sorry %s, You lost!" %(user_name)
attempts = 0
maximum_attempts = 7
user_number = int(raw_input())
attempts += 1
print "You have %s lives left." %(maximum_attempts - attempts)
while True:
if user_number == random_number:
print vectory_message
attempts = 0
second_chance()
elif user_number > random_number:
user_number = int(raw_input("A bit lower ..."))
attempts += 1
if attempts == maximum_attempts:
print defeat_message
second_chance()
print "You have %s lives left." %(maximum_attempts - attempts)
continue
elif user_number < random_number:
user_number = int(raw_input("Guess higher ..."))
attempts += 1
if attempts == maximum_attempts:
print defeat_message
second_chance()
print "You have %s lives left." %(maximum_attempts - attempts)
continue
def second_chance():
while True:
choice = raw_input("wanna give it another shot?(y/n)")
if choice == "y":
gameloop()
elif choice == "n":
quit()
else:
print "That wasn't a (y) or (n)!, Try again."
continue
gameloop()