I am getting some syntax error in sublime text and red highlight on elif command in my text.
i am a beginner in coding so their may be some problem that i can't notice.
1
pylint: error E0001 - invalid syntax (<unknown>, line 49) (syntax-error)
print("-------------Welcome User-------------")
choice = 0
while TRUE:
print("1.Square.")
print("2.Rectangle.")
print("3.Circle.")
choice = int(input("Enter your choice : "))
if choice == 1:
print("1.Area.")
print("2.Perimeter.")
ch = int(input("Enter your choice : "))
if ch == 1:
l = float(input("Enter the length : "))
area = l * l
print("The area is : ",area)
elif ch == 2:
l = float(input("Enter the length : "))
per = 4 * l
print("The perimeter is : ",per)
else:
print("Wrong choice\n")
i = input()
elif choice == 2:
print("1.Area")
print("2.Perimeter.")
ch = int(input("Enter your choice : "))
if ch == 1:
l = float(input("Enter the length : "))
b = float(input("Enter the breadth : "))
area = l * b
print("The area is : ",area)
elif ch == 2:
l = float(input("Enter the length : "))
b = float(input("Enter the breadth : "))
per = 2*(l + b)
print("The perimeter is : ",per)
else:
print("Wrong Choice\n")
i = input()
elif choice == 3:
print("1.Area")
print("2.Circumference")
ch = int(input("Enter your choice : ")
if ch == 1:
r = float(input("Enter the radius : "))
print("The area is : ",r*r*3.14)
elif ch == 2:
r = float(input("Enter the radius : "))
print("The perimeter is : ",2*3.14*r)
else:
print("Wrong choice.")
i = input()
In the elif choice == 3 block, you have this line:
ch = int(input("Enter your choice : ")
That line causes the error, because you're missing the closing parentheses on the end.
Related
This code shows run time error as NZEC. Tried both the ways by input() and raw_input still shows error.
# A = int(input('Enter the amount of A: '))
# B = int(input('Enter the amount of B: '))
A, B = raw_input().split(" ")
A = int(A)
B = int(B)
if (A > 0 and B > 0):
print('The mixture is a solution: ')
elif (A == 0):
print('The mixture is Liquid: ')
elif (B == 0):
print('The mixture is Solid: ')
else:
print('Invalid Entry')
In Python 3 there are no raw_input because all inputs are raw_input.
Given that the code works correctly and doesn't throw an error:
A = int(input('Enter the amount of A: '))
B = int(input('Enter the amount of B: '))
if (A > 0 and B > 0):
print('The mixture is a solution: ')
elif (A == 0):
print('The mixture is Liquid: ')
elif (B == 0):
print('The mixture is Solid: ')
else:
print('Invalid Entry')
print("Welcome to The pyCalc")
print("For Addition press 1")
print("For Multiplication press 2")
print("For Subtraction press 3")
print("For Division press 4")
flag = 'y'
while flag == 'y':
x = float(input("Enter your Choice(1-4): "))
if x == 1:
a = float(input("Enter 1st Value: "))
b = float(input("enter 2nd Value: "))
c = a+b
print("Sum: ", int(c))
elif x == 2:
a = float(input("Enter 1st Value: "))
b = float(input("Enter 2nd Value: "))
c = a*b
print("Product: ", int(c))
elif x == 3:
a = float(input("Enter the 1st value: "))
b = float(input("Enter the 2nd value: "))
c = a - b
print("Difference: ", int(c))
elif x == 4:
a = float(input("Enter the 1st value: "))
b = float(input("Enter the 2nd value: "))
c = a // b
print("Quotient: ", c)
else:
print("error !")
flag = print(input("Do you want to calculate more(y/n)? : ", y))
if flag == y:
continue
Hi, I'm actually new to Python so not really familiar with even basic concepts. so in this calculator program, after the first run, i want the code to rerun when the user gives an input of y. According to my knowledge, this is possible using a while loop in which we put the main code in its body and give a condition using if statement and the secondly by using the continue statement. Can somebody explain whats wrong here.
p.s. indentation may be wrong in some cases.
I have re-written your code because there were two issues:
There's no such thing as print(input(""))
flag = input("Do you want to calculate more(y/n)? : ") should be outside else
print("Welcome to The pyCalc")
print("For Addition press 1")
print("For Multiplication press 2")
print("For Subtraction press 3")
print("For Division press 4")
flag = 'y'
while flag == 'y':
x = float(input("Enter your Choice(1-4): "))
if x == 1:
a = float(input("Enter 1st Value: "))
b = float(input("enter 2nd Value: "))
c = a+b
print("Sum: ", int(c))
elif x == 2:
a = float(input("Enter 1st Value: "))
b = float(input("Enter 2nd Value: "))
c = a*b
print("Product: ", int(c))
elif x == 3:
a = float(input("Enter the 1st value: "))
b = float(input("Enter the 2nd value: "))
c = a - b
print("Difference: ", int(c))
elif x == 4:
a = float(input("Enter the 1st value: "))
b = float(input("Enter the 2nd value: "))
c = a // b
print("Quotient: ", c)
else:
print("error !")
flag = input("Do you want to calculate more(y/n)? : ")
if flag.lower() == "y":
continue
I just created a simple calculator program using python language, but there is a little problem here, when I end the program by inputting number 1, there is always the text none.
The question is how do I get rid of the text none in the program that I created? Because to be honest it is very annoying and will damage the image of the program that I created.
def pilihan():
i = 0
while i == 0:
print('\n\tWelcome to the Simple Calculator Program')
print("\nPlease Select Existing Operations", "\n1. subtraction", "\n2. increase", "\n3. division", "\n4. multiplication")
pilihan2 = int(input('Enter your choice (1/2/3/4): '))
if pilihan2 == 1:
angka1 = int(input('Enter the First Number: '))
angka2 = int(input('Enter the Second Number: '))
print(angka1, "-", angka2, "=", angka1 - angka2)
elif pilihan2 == 2:
angka1 = int(input('Enter the First Number: '))
angka2 = int(input('Enter the Second Number: '))
print(angka1, "+", angka2, "=", angka1 + angka2)
elif pilihan2 == 3:
angka1 = int(input('Enter the First Number: '))
angka2 = int(input('Enter the Second Number: '))
print(angka1, ":", angka2, "=", angka1 / angka2)
elif pilihan2 == 4:
angka1 = int(input('Enter the First Number: '))
angka2 = int(input('Enter the Second Number: '))
print(angka1, "x", angka2, "=", angka1 * angka2)
else:
print('Error option, please try again')
continue
print('Program finished, want to restart?')
y = 0
while y == 0:
ulang = int(input('Type 0 for YES and 1 for NO = '))
if ulang == 0:
y += 1
break
elif ulang == 1:
y += 2
break
else:
print('\nThe command you entered is an error, please try again')
continue
if y == 1:
continue
else:
break
print(pilihan())
Change the print(pilihan()) to pilihan(), the return value of pilihan() is None :)
This question already has answers here:
In Python, how do I check that the user has entered a name instead of a number?
(3 answers)
Asking the user for input until they give a valid response
(22 answers)
Closed 3 years ago.
Let's get straight to the problem: when i run the code, and type letters instead of numbers to the first input my python gets an error. How do i make my python know that if someone types in letters instead of numbers should get warned and repeat the code? Im trying to fix it from about two hours.
Thank you for help
Also sorry for my really bad english
import time
import random
def repeatt():
od = int(input("Wpisz do ktorej liczby liczba ma byc losowana: "))
doo = int(input("Do ktorej: "))
if od >= doo:
print("Jeszcze raz :")
repeatt()
elif od <= doo:
wylosowana = random.randint(od, doo)
print("Wylosowana liczba: ", wylosowana)
print("Witaj! Od czego chcialbys zaczac?:")
print(
"""
1. forin slowo
2. oblicz ile ja zyje
3. oblicz, ile mam zaplacic
4. tekst
5. losowanie liczby
"""
)
choice = int(input("Wpisz liczbe: "))
if choice == 1:
slowo = input("Wprowadz slowo: ")
for letter in slowo:
print(letter)
elif choice == 2:
obliczanie = int(input("Wprowadz, ile masz lat: "))
oblicz = obliczanie * 60 * 60
print("Zyjesz juz ponad ", obliczanie * 60 * 60, "sekund")
elif choice == 3:
pieniadze = int(input("Ile podczas miesiacu zarabiasz?: "))
print("Na jedzenie: ", pieniadze / 5)
elif choice == 4:
wiadomosc = input("Wpisz jakąs wiadomosc: ")
def repeat():
wybor = input("upper, lower, title?: ")
if wybor == "upper":
print(wiadomosc.upper())
elif wybor == "lower":
print(wiadomosc.lower())
elif wybor == "title":
print(wiadomosc.title())
else:
print("Wpisz upper, lower lub title")
wybor = input("upper, lower, title?: ")
if wybor == "upper":
print(wiadomosc.upper())
elif wybor == "lower":
print(wiadomosc.lower())
elif wybor == "title":
print(wiadomosc.title())
else:
print("Wpisz proprawnie")
repeat()
elif choice == 5:
od = int(input("Wpisz liczbe od ktorej ma byc losowana: "))
doo = int(input("Do ktorej: "))
if od >= doo:
print("Jeszcze raz :")
repeatt()
elif od <= doo:
wylosowana = random.randint(od, doo)
print("Wylosowana liczba: ", wylosowana)
else:
print("Tylko liczby")
else:
print("Wpisz liczbe od 1 do 3")
choice = int(input("Wpisz liczbe: "))
Replace the above line with below code
While True:
choice = input("Wpisz liczbe: ")
if choice.isdigit():
choice = int(choice)
# your code of if conditions
else:
print("please enter valid input")
continue
while True:
try:
choice = int(input("Wpisz liczbe: "))
break
except ValueError:
print("No letters allowed, please try again")
def repeatt():
def redo(): #Repeating function
try:
od = int(input("Wpisz do ktorej liczby liczba ma byc losowana: "))
except: #If the user enters a string instead of int it will go back to redo() which will repeat until user enters a int.
print("Enter A Number!")
redo()
redo() #Leads to the input
repeatt()
I wanted to add a confirmation for my code so that the user will be able to change their input. I haven't yet added the loop for the question but for some reason when I run this it fails to run def calc() and therefore the calculations I created cannot continue. Help!!
n=0
x=0
while True:
numbers = input("Please enter a, b,c, or, d to select a equation")
if numbers == "a":
n =3
x = 2
break
elif numbers =="b":
n = 4
x = 5
break
elif numbers == "c":
n=5
x=6
break
elif numbers == "d":
n=6
x=7
break
else:
print("Please enter a,b,c, or d")
w = float(input("Please enter weight"))
choice = input("Is this your answer?")
if choice == "yes":
def calc():
if n > w :
weight = (x - w)
weight2 = weight/n
print(weight)
elif w < x:
weight = (w - x)
weight2 = weight/n
print(weight)
calc()
elif choice =="no":
print ("Lets change it")
else:
print("Please respond with 'yes' or 'no'")