Skip to content

Instantly share code, notes, and snippets.

@uroybd
Created July 14, 2016 17:38
Show Gist options
  • Save uroybd/e20d1e1c4a8c01ca55761f004ac3915d to your computer and use it in GitHub Desktop.
Save uroybd/e20d1e1c4a8c01ca55761f004ac3915d to your computer and use it in GitHub Desktop.
URI 1118 python
def get_input():
inp = float(input())
if inp > 10 or inp < 0:
print("nota invalida")
return get_input()
else:
return inp
def calculate():
a = get_input()
b = get_input()
return (a + b)/2
def redo():
X = float(input())
print("novo calculo (1-sim 2-nao)")
if X < 1 or X > 2:
print("novo calculo (1-sim 2-nao)")
redo()
elif int(X) == 2:
return False
elif int(X) == 1:
return True
while True:
print("media = " + str(calculate()))
x = redo()
if not x:
break
@LaZyRaifur
Copy link

my code faced with run time error? can you please explain why it's happen my code is given below :
n = 0
c= 0
while 1:
x = float(input())
if(x >= 0 and x<=10.0):
n += 1
c += x
if n == 2:
print("media = %.2f"%(c/2))
n = 0
c = 0
temp = int(input("novo calculo (1-sim 2-nao)"))
if temp == 2:
break
elif temp == 1:
continue
else:
temp = int(input("novo calculo (1-sim 2-nao)"))

else:
    print("nota invalida")

@uroybd
Copy link
Author

uroybd commented Sep 2, 2020

my code faced with run time error? can you please explain why it's happen my code is given below :
n = 0
c= 0
while 1:
x = float(input())
if(x >= 0 and x<=10.0):
n += 1
c += x
if n == 2:
print("media = %.2f"%(c/2))
n = 0
c = 0
temp = int(input("novo calculo (1-sim 2-nao)"))
if temp == 2:
break
elif temp == 1:
continue
else:
temp = int(input("novo calculo (1-sim 2-nao)"))

else:
    print("nota invalida")

Your indentation is broke. Can you please fix it so that I can read it properly? Also, be more elaborate. What are you trying to achieve? And what sort of error you're getting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment