사용자가 가격을 입력 한 후 프로그램이 입력을 기반으로 배송비를 출력하는 작은 프로그램을 작성하고 있습니다.사용자 입력에 따라 오른쪽 else 문 선택
#Initilaize variables
lowUS = 6.00;
medUS = 9.00;
highUS = 12.00;
lowCan = 8.00;
medCan = 12.00;
highCan = 15.00;
#Greet user and ask for input
print("Welcome to Ben's shipping calculator!");
print("We will calculate your shipping cost for you!");
orderTotal = float(input("Please input your total amount."));
country = input("In which country do you reside? Please type C for Canada or U or USA. ");
#Validate input
while country not in {'u', 'c', 'C', 'U'}:
print ("Invalid input. Please try again. ")
country = input("In which country do you reside? Please type C for Canada or U or USA. ");
#Determine how much the shipping fee is
if country == 'U' or country == 'u':
if orderTotal <= 50.00:
if orderTotal > 50.00 and orderTotal <= 100.00:
if orderTotal > 100.00 and orderTotal <= 150.00:
if orderTotal > 150.00:
print("Your shipping is free and your grand total is", orderTotal)
else:
print("Your shipping fee is: ", highUS);
orderTotal = (orderTotal + highUS);
else:
print("Your shipping fee is: ", medUS);
orderTotal = (orderTotal + medUS);
else:
print("Your shipping fee is: ", lowUS);
orderTotal = (orderTotal + lowUS);
elif country == 'c' or country == 'C':
if orderTotal <= 50.00:
if orderTotal > 50.00 and orderTotal <= 100.00:
if orderTotal > 100.00 and orderTotal <= 150.00:
if orderTotal > 150.00:
print("Your shipping is free and your grand total is", orderTotal)
else:
print("Your shipping fee is: ", highCan);
orderTotal = (orderTotal + highCan);
else:
print("Your shipping fee is: ", medCan);
orderTotal = (orderTotal + medCan);
else:
print("Your shipping fee is: ", lowCan);
orderTotal = (orderTotal + lowCan);
print("Your grand total is: $", orderTotal);
나는 파이썬 프로그래밍에 아주 새로운 오전 나는이 그것을 갈 수있는 좋은 방법입니다 있는지 확실하지 않습니다,하지만 나는 그것을 시도 줄 것이라고 생각 때문에 나는 경우 - 다른 진술을 배우고 . 지금까지는 금액에 "50"을 입력 한 경우에만 작동합니다. 그것은 "50"에 대해서만 국가 기준으로 계산합니다. 나는 누군가가 도울 수 있고 설명 할 수 있다면 내가 잘못한 곳인지 잘 모르겠다.
첫 번째'if'는 50보다 작거나 같은 경우에만 입력됩니다. 다음 번 확인은 50보다 큰 경우입니다. 그러면 블록이 실행되지 않습니다. 'else' 절은 실행할 수있는 유일한 것입니다 ... –
파이썬은 개행 문자 외에 줄 종결 자도 없습니다. 세미콜론은 완전히 불필요합니다. 이것은 C가 아닙니다! (또는 자바, 또는 자바 스크립트, 또는 다른 무엇이든지) – MattDMo