Как сравнить строки с пробелами внутри?
У меня проблема с моим кодом Python. Сравнение строк для переменной
planet_choice
работает только в том случае, если я ввожу точно слово, но не тогда, когда вокруг слова есть пробелы.
Пример
мне нужно написать
"Venus"
. Когда я использую
" Venus"
или что-то в этом роде, я получаю сообщение об ошибке.
Код
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")
Можете ли вы помочь мне с этой проблемой или есть предложения по улучшению?