Hi,how can i use this code only 10 tries? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Hi,how can i use this code only 10 tries?

#Guess number import random number = random.randint(1,100) quess = int(input("Отгадай число:")) tries = 1 while quess != number: if quess > number: print("МЕНЬШЕ") else: print("Больше") quess = int(input("Ваше предложение")) tries +=1 print("Вы отгадали число", number) print("На это ушло", tries, "раз") print("\n\n\nВведите Enter")

17th Oct 2021, 7:11 AM
Александр Козак
5 Answers
+ 2
#add this tries +=1 if tries > 9: print("На это ушло", tries, "раз") break
17th Oct 2021, 7:29 AM
Simba
Simba - avatar
0
Simba, "На это ушло {tries} раз" means "This took {tries} tries" in Russian, so, I guess, it should be: ``` #... while quess != number: #... tries += 1 if tries > 9: print("Вы проиграли.") # means "You lost." break # (English) go out of `while` loop / (русский) выйти с цикла `while` else: # (English) if `break` command was not executed / (русский) если команда `break` не была выполнена print("Вы отгадали число:", number) # means "You guessed the number: {number} print("На это ушло", tries, "раз.") #... ``` Where "#..." means the original code and text after "#" is just explanation and does not matter.
17th Oct 2021, 7:52 AM
#0009e7 [get]
#0009e7 [get] - avatar
0
So i found my question: Игра "отгадай число"   import random   print("\tДобро пожаловать в игру 'Отгадай число'!") print("Компьютер загадал натуральное число из диапазона от 1 до 100.") print("Вам нужно угадать его за максимум 5 попыток.\n")   # Начальные значения the_number = random.randint(1, 100) guess = int(input("Ваше предположение: ")) tries = 1   # Цикл отгадывания while guess != the_number: if guess > the_number: print("Меньше...") elif guess < the_number: print("Больше...") if guess > the_number and tries >= 6: print("Соберись, тряпка!") elif guess < the_number and tries >= 6: print("Неудачник!")   guess = int(input("\nВаше предположение: ")) tries += 1   print("\nПоздравляю! Вам удалось отгадать число!") print("вы затратили всего лишь", tries, "попытки(ок)!") if tries >= 6: print("\nВсего лишь", tries, "попытки(ок)), Карл?! Да ты издеваешься?")   input("\nНажмите Enter, чтобы покинуть игру...")
17th Oct 2021, 10:14 AM
Александр Козак
- 1
You are right, the code has to print "you use 10 " ,tries, " stop,get out here"
17th Oct 2021, 8:13 AM
Александр Козак
- 1
What should i do this block? print("Вы отгадали число" ,number) prtint("На это ушло",tries , "раз")
17th Oct 2021, 8:21 AM
Александр Козак