Python Forum
Function: SyntaxError: invalid syntax
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function: SyntaxError: invalid syntax
#3
I was kind of confused at the beginning because your program has a huge problem which would result in a TypeError not a SyntaxError, took me some moments to see, that you are missing a ) in line 3.
The next problem you will run into is that the + operator is not allowed between strings and numbers, so "test: " + 1 will result in a TypeError, there are different approaches to get the number in the string. The best one would be format.
print(f"The monthly rent amount is {x * 52 / 12}")
here the part between the curly brackets will be filled with your calculation and you do not have to worry about the data type you are putting in there. The easiest way, at least at the beginning would be to cast the value you are recieving to string
print("The monthly rent amounnt is " + str(x * 52 / 12))
Reply


Messages In This Thread
Function: SyntaxError: invalid syntax - by vejin - Feb-02-2020, 08:14 PM
RE: Function: SyntaxError: invalid syntax - by ThiefOfTime - Feb-02-2020, 09:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  print(data) is suddenly invalid syntax db042190 6 3,321 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  [Solved] unkown (to me) function def parm "name1:name2" syntax. MvGulik 5 2,193 Nov-11-2022, 11:21 AM
Last Post: MvGulik
  meaning of -> syntax in function definition DrakeSoft 5 3,540 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  SyntaxError: invalid syntax ?? korenron 15 9,920 Jan-25-2022, 11:46 AM
Last Post: korenron
  Invalid syntax with an f-string Mark17 7 16,149 Jan-14-2022, 04:44 PM
Last Post: Mark17
  invalid syntax in my class CompleteNewb 2 3,307 Dec-13-2021, 09:39 AM
Last Post: Larz60+
Star I'm getting syntax error while using input function in def. yecktmpmbyrv 1 2,770 Oct-06-2021, 09:39 AM
Last Post: menator01
Exclamation Invalid syntax error(Predict Ethereum Price) lulu43366 2 4,332 Sep-24-2021, 01:24 PM
Last Post: lulu43366
  Tuple generator, and function/class syntax quazirfan 3 6,743 Aug-10-2021, 09:32 AM
Last Post: buran
  Unexplained Invalid syntax Error cybertooth 5 5,570 Aug-02-2021, 10:05 AM
Last Post: cybertooth

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020