Выполнение операторов if и else в последнем блоке - PullRequest
2 голосов
/ 12 февраля 2020
RAM = int(input("RAM amount: "))
if RAM >= 8:
 print ("Your RAM is good")
else:
 print ("not enough RAM")

HDD = int(input("Enter HDD or SSD storage space: "))
if HDD >=55:
 print("You have enough space")
else:
 print("You do not have enough space")

OS = input("Input Windows version ex: Windows 10: ")
if OS=="Windows 10":
 print ("You meet the minimum OS requirement")
if OS=="Windows 8.1":
 print ("You meet the minimum OS requirement")
if OS=="Windows 7":
 print ("You meet the minimum OS requirement")
if OS=="Linux":
 print("This OS is not supported")
if OS=="Mac":
 print("This OS is not supported")
else:
 print("Your OS does not meet the minimum requirements")

Не уверен, почему оба «Вы соответствуете минимальному требованию к ОС» и «Эта ОС не поддерживается» оба печатают при вводе значения.

1 Ответ

3 голосов
/ 12 февраля 2020

Ваши if блоки не являются дополнением. Сделайте их дополнением, используя elif. В противном случае оператор else будет дополнен последним оператором if, именно поэтому вы получили два вывода вместо одного.

OS = input("Input Windows version ex: Windows 10: ")
if OS == "Windows 10":
    print ("You meet the minimum OS requirement")
elif OS == "Windows 8.1":
    print ("You meet the minimum OS requirement")
elif OS == "Windows 7":
    print ("You meet the minimum OS requirement")
elif OS == "Linux":
    print("This OS is not supported")
elif OS == "Mac":
    print("This OS is not supported")
else:
    print("Your OS does not meet the minimum requirements")
...