Написать игру в которой надо будет угадывать номер который загадал бот

на каком языке?

На английском

Ответ
5 (1 оценка)
1
Stoshyshek2007 1 год назад
Светило науки - 15 ответов - 0 раз оказано помощи

import time

import random

print('!TYPE "STOP" TO LOSE GAME AND GET A NUM!')

attempts = 1

rounds_counter = 1

tours = []

while True:

   print('----------------------- round {} ----------------------- '.format(rounds_counter))

   while True:

       try:

           max_nuber = int(input('which max number you wanna see? '))

       except ValueError:

           print('you can use only numbers!!!')

       else:

           break

       

   right_num = random.randint(1, max_nuber)

#   print(right_num)

   print('attempt', attempts)

   users_num = input('ur num ')  

   if users_num.lower() == 'stop':

       print(right_num)

       print("u've lost")

       again = str(input('again? - '))

       if again.lower() == 'yes':

           print ('ok')

           tours.append('round #{} - defeat - total attempts: {} - max number {}'.format(rounds_counter, attempts, max_nuber))

           attempts = 1

           

       elif again.lower() == 'no':

           tours.append('round #{} - defeat - total attempts: {} - max number {}'.format(rounds_counter, attempts, max_nuber))

           print('rounds history : ')

           for tour in tours:

               print(tour)

                   

           break

           print('Good Bye & Good Riddance!')

   else:

       users_num = int(users_num)

       while users_num != right_num:

           if str(users_num).lower() == 'stop':

               print (right_num)

               break

           else:

               print('incorrect')

               attempts += 1

               print ('attempt', attempts)

               users_num = input('ur num ')

               if str(users_num).lower() == 'stop':

                   print (right_num)

                   break

               else:

                   users_num = int(users_num)

       if users_num == right_num:

           print ('u won')

           print('total attempts - {}'.format(attempts))

           again = str(input('again? - '))

           if again.lower() == 'yes':

               print ('ok')

               tours.append('round #{} - victory - total attempts: {} - max number {}'.format(rounds_counter, attempts, max_nuber))

               rounds_counter += 1

               attempts = 1

           else:

               tours.append('round #{} - victory - total attempts: {} - max number {}'.format(rounds_counter, attempts, max_nuber))

               print('rounds history : ')

               for tour in tours:

                   print(tour)

               print('Good Bye & Good Riddance!')

               break

               

       else:

           print("u've lost")

           print('total attempts - {}'.format(attempts))

           again = str(input('again? - '))

           if again.lower() == 'yes':

               print ('ok')

               tours.append('round #{} - defeat - total attempts: {} - max number {}'.format(rounds_counter, attempts, max_nuber))

               rounds_counter += 1

               attempts = 1

               

               

           elif again.lower() == 'no':

               tours.append('round #{} - defeat - total attempts: {} - max number {}'.format(rounds_counter, attempts, max_nuber))

               print('rounds history : ')

               for tour in tours:

                   print(tour)

                   time.sleep(.5)

                   

               break

               print('Good Bye & Good Riddance!')

Остались вопросы?