-2

I have a problem with my Python code. The string comparison for variable planet_choice only works, if I input exactly the word, but not when there are spaces around the word.

Example

I need to write "Venus". When I use " Venus" or something like that I get an error.

Code

import time

print("Hey ich helfe dir zu berechnen, wie Schwer du auf den verschiedenen Planeten bist ;)")
time.sleep(3)
user_weight = input("Wie viel wiegst du?")
time.sleep(1)
print("Es gibt 6 verschiedene Planeten zur Auswahl")
time.sleep(1.5)
print("Venus")
time.sleep(1.5)
print("Mars")
time.sleep(1.5)
print("Jupiter")
time.sleep(1.5)
print("Saturn")
time.sleep(1.5)
print("Uranus")
time.sleep(1.5)
print("Neptun")
time.sleep(1.5)
planet_choice = input("Für welchen Planeten entscheidest du dich?")
if planet_choice == "Venus":
    weight = float(user_weight) * 0.91
elif planet_choice == "Mars":
    weight = float(user_weight) * 0.38
elif planet_choice == "Jupiter":
    weight = float(user_weight) * 2.34
elif planet_choice == "Saturn":
    weight = float(user_weight) * 1.06
elif planet_choice == "Uranus":
    weight = float(user_weight) * 0.92
elif planet_choice == "Neptun":
    weight = float(user_weight) * 1.19
print("Dein Gewicht beträgt auf dem Planet " + planet_choice + " " + str(round(weight)) +" kg")

Can you help me with this problem or have suggestions for improvement?

hc_dev
  • 5,553
  • 20
  • 27
AF611
  • 1
  • 1

0 Answers0