I want to add a while statement.

Asked 1 years ago, Updated 1 years ago, 369 views

I'd like to add a while statement to 1<=X<=89 (when it's not a big luck or a big luck).
Where and how should I add it?

import random
x = random.randint (1,99)

z=int(input('1).Start the omikuji.'))
if z == 2:
  print('1.')
else:
  if x<10:
    print('The number',x,' was bad.')
  if9<x<30:
    print('Number',x,' was Sueyoshi.')
  if 29<x<50:
    print('The number',x,' was lucky.')
  if 49<x<70:
    print('The number',x,' was Kokichi.')
  if 69<x<90:
    print('Number',x,' was Nakayoshi.')
  if89<x<99:
    print('The number',x,' was a lucky one.')
  if x == 99:
    print('The numbers',x,' were great luck.')

python

2023-03-07 00:55

1 Answers

You can use break to exit while by enclosing the entire while.

import random
x = random.randint (1,99)

while True:
    z=int(input('1).Start the omikuji.'))
    if z == 2:
      print('1.')
    else:
      if x<10:
        print('The number',x,' was bad.')
      if9<x<30:
        print('Number',x,' was Sueyoshi.')
      if 29<x<50:
        print('The number',x,' was lucky.')
      if 49<x<70:
        print('The number',x,' was Kokichi.')
      if 69<x<90:
        print('Number',x,' was Nakayoshi.')
      if89<x<99:
        print('The number',x,' was a lucky one.')
        break
      if x == 99:
        print('The numbers',x,' were great luck.')
        break


2023-03-07 13:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.