Python Forum
Mysterious syntax errors... help?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mysterious syntax errors... help?
#1
Trying to code, but keep on getting syntax errors. It says 'answer =' and 'return output
are improper. I am using python 3

def exponential():	base = int(input('Your base number:'))	exponent = int(input('Your exponential'))	answerexp = base ** exponent	output = '%s to the power of %s equals %s'%(str(base),str(exponent),str(answer))	return output def minus():	num1 = int(input('Your 1st number: '))	num2 = int(input('Your 2nd number: '))	answer = num1 - num2	output = "%s minus %s is equal to %s"%(str(num1),str(num2),str(ans))	return output def add():	num1 = int(input('Your 1st number: '))	num2 = int(input('Your 2nd number: '))	answer = num1 + num2	output = "%s plus %s is equal to %s" %(str(n1),str(n2),str(ans))	return output def sqroot():	number = int(input('Your number: '))	output = number ** (1. / 2)	return output def root():	exponent = int(input('Your number to root: '))	root = int(input('Your root to be used: '))	answer = exponent ** (1. / root)	output = '%s with the root of %s is %s'%(str(exponent),str(root),str(answer)	return output def func():	func = input("What do you want to do? ").lower()	if func == 'divide':	answer = divide()	print(answer)	func()	elif func == 'multiply' or 'times':	answer = multiply()	print(answer)	func()	elif func == ('power' or 'exponent') or ('exponential' or 'exponents'):	answer = exponential()	print(answer)	func()	elif func == 'minus' or 'subtract':	answer = minus()	print(answer)	func()	elif func == 'root':	answer = root()	print(answer)	func
Reply
#2
On line 27 you're missing a close-parenthesis.
Reply
#3
(Apr-26-2018, 08:50 PM)micseydel Wrote: On line 27 you're missing a close-parenthesis.

I have fixed that, but the errors persist.
Reply
#4
When I take your code and make that one change, I don't get a syntax error. What's the exact, latest code you're using, along with its full error message? If you're using an IDE, it'd probably be worth getting the error message by using a terminal / console.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax errors: Struggling to setup enviroment and load packages AH56 5 4,658 Jun-30-2021, 01:01 PM
Last Post: AH56
  Pip Syntax Errors in CMD: Windows 10 and Python 3.8.1 jamesphopper 2 7,355 Feb-08-2020, 07:21 PM
Last Post: jamesphopper
  Mysterious Indentation Problem Dakodak 11 7,636 Jun-24-2019, 06:23 AM
Last Post: Dakodak
  Mysterious Extra New-Line trevorkavanaugh 2 3,684 Feb-27-2019, 07:13 PM
Last Post: trevorkavanaugh
  random syntax errors s4lty_b0i 3 4,477 Nov-26-2017, 03:45 PM
Last Post: heiner55
  y syntax errors? Saxycool12345 3 4,937 Sep-16-2017, 01:24 PM
Last Post: sparkz_alot
  Decorator toy code throws syntax errors kevinxhi 3 5,115 Sep-04-2017, 03:01 AM
Last Post: kevinxhi
  Syntax errors jon65 22 26,462 Aug-20-2017, 01:26 PM
Last Post: jon65

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.