но когда я ставил def main(), он мгновенно завершал код, где бы я ни помещал def main (). Может ли кто-нибудь мне помочь?
Вот код.
Код: Выделить всё
import time
import random
maxn=100
minn=1
print('Hi! Whats Your Name?')
name = input()
print(f'Well {name}, Welcome to guess the number.')
time.sleep(1)
print('To Begin, guess a number 1 to 100.')
time.sleep(1)
def main():
print('We will begin in,')
time.sleep(1)
print('3')
time.sleep(1)
print('2')
time.sleep(1)
print('1')
time.sleep(1)
print('GO GO GO')
att = 0
n = random.randint(minn, maxn)
guess = None
while guess !=n:
guess = int(input('Your Guess < '))
att += 1
if guess > n + 10:
print('Too High. Try Again')
if guess < n - 10:
print('Too Low. Try Again')
if guess > n and guess < n + 11:
print('Close but still a bit high.')
if guess < n and guess > n - 11:
print('Close but still a bit low.')
if guess == n:
print(f"Congratulations {name}, The number was {n}. You gussed it in {att} tries!")
print('')
print('Would you like to play Again?')
choice = input('Yes or No < ').lower()
while not choice.lower != ('yes', 'Yes', 'no', 'No'):
choice = input('Yes or No < ').lower()
if choice == ('no', 'No'):
print('Ok. Thanks for playing. Byeeee')
if choice == ('yes', 'Yes'):
print('Ok. Restarting Program.')
time.sleep(1)
print('...')
time.sleep(1)
print('...')
time.sleep(1)
print('...')
main()
Код: Выделить всё
main()
Код: Выделить всё
if __name__ == '__main__':
main()
Подробнее здесь: https://stackoverflow.com/questions/790 ... ot-working