-1
umbrella = input("Which umbrella are you going to use? Select between a,b,c,d,e \n")

if umbrella == "a":
    amount_new_umbrellas = math.ceil(x / 45500)
    print("umbrellas type a: "+ str(amount_new_umbrellas))

elif umbrella == "b":
    amount_new_umbrellas = math.ceil(x / 16700)
    print("umbrellas type b: "+ str(amount_new_umbrellas))

elif umbrella == "c":
    amount_new_umbrellas = math.ceil(x / 27800)
    print("umbrellas type c: "+ str(amount_new_umbrellas))

elif umbrella == "d":
    amount_new_umbrellas = math.ceil(x / 7600)
    print("umbrellas type d: "+ str(amount_new_umbrellas))

elif umbrella == "e":
    amount_new_umbrellas = math.ceil(x / 13800)
    print("umbrellas type e: "+ str(amount_new_umbrellas))

else:
    print("Data Error")

I need to improve the code using a WHILE loop, primary, to keep asking the user for an input that has to be (a,b,c,d,e)

mkrieger1
  • 19,194
  • 5
  • 54
  • 65

1 Answers1

0
import math
umbrella = input("Which umbrella are you going to use? Select between a,b,c,d,e \n")
x = 100
amount_new_umbrellas = {
    "a" : math.ceil(x / 45500),
    "b" : math.ceil(x / 16700),
    "c" : math.ceil(x / 27800),
    "d" : math.ceil(x / 7600),
    "e" : math.ceil(x / 13800),
}.get(umbrella)
if amount_new_umbrellas:
   print("umbrellas type "+str(umbrella)+": "+ str(amount_new_umbrellas))
else:
  print("Data Error")


you can add a loop and it work

import math
while True:
  umbrella = input("Which umbrella are you going to use? Select between a,b,c,d,e \n")
  x = 100
  amount_new_umbrellas = {
      "a" : math.ceil(x / 45500),
      "b" : math.ceil(x / 16700),
      "c" : math.ceil(x / 27800),
      "d" : math.ceil(x / 7600),
      "e" : math.ceil(x / 13800),
  }.get(umbrella)
  if amount_new_umbrellas:
    print("umbrellas type "+str(umbrella)+": "+ str(amount_new_umbrellas))
  else:
    print("Data Error")
    break

tomerar
  • 805
  • 5
  • 10