저는 파이썬에 대해 상당히 새로운 초보자입니다. 서브 루틴으로 코드를 작성하여 가장 큰 수와 가장 작은 수 및 그 수 사이의 범위를 찾습니다. 그러나 테스트 데이터 x = 12, y = 6, z = 2는 가장 큰 숫자가 y임을 보여 주지만 테스트 데이터에 대한 대답은 잘못된 것입니다.Python. 잘못된 결과
노트 : 입력() 문자열을 반환하기 때문에 변수가 너무 코드에서
x = input("Enter x:")
y = input("Enter y:")
z = input("Enter z:")
if x>y and x>z :
output1 = 'x is the largest'
large = x
elif (y>x and y>z):
output1 = 'y is the largest'
large = y
elif (z>x and z>y):
output1 = 'z is the largest'
large = z
else :
output1 ='all numbers are equal'
large = 0
if x<y and x<z :
output2 = 'x is the smallest'
small = x
elif (y<x and y<z):
output2 = 'y is the smallest'
small = y
elif (z<x and z<y):
output2 = 'z is the smallest'
small = z
else :
output2 = 'all numbers are equal'
small = 0
output3 = large-small
outputq = "Bye"
print("[1] Find the highest variable.")
print("[2] Find the lowest variable.")
print("[3] Find the range between the highest and the lowest variables.")
print("[q] Quit.")
while outputq == ('Bye'):
choice = input("Enter choice number:")
if choice == '1' :print (output1)
elif choice == '2' :print (output2)
elif choice == '3' :print (output3)
elif choice == 'q' :
print (outputq)
outputq="end"
input()
FYI : "서브 루틴"은 일반적으로 Python에서 _functions_라고합니다. 하지만 실제로, 당신의 코드에 어떤 함수도 보이지 않습니다. –
최저 변수/최고 변수/범위와 같은 3 가지 다른 용도를 의미했습니다 –
https://stackoverflow.com/questions/20449427/how-can-i-read-inputs-as-integers https://stackoverflow.com/questions/4915361/whats-the-difference-raw-input-and-input-in-python3-x –