• Register
1 vote


I am a python newbee. I was trying to  print string and int on same line of a python code. The code I wrote is:

a = int(input("Please Enter a Number: "))
print("Your Number is" a)

but when I run this it shows an error message:

File "main.py", line 2
    print("Your Number is" x)
SyntaxError: invalid syntax

I am not able to do this please help me to solve this problem?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

1 vote


You sould put a comma(,) before your a to get no errors. So write your code like:

a = int(input("Please Enter a Number: "))

print("The number is", a)

And yo will get an output like:

Please Enter a Number: 12
The number is 12

or you can also write your code like:

a = int(input("Please Enter a Number: "))

print("The number is " + str(a))

Happy coding.

11 6 4
34,950 points

Related questions

0 votes
1 answer 37 views
Problem: I've got some Python code that runs through a list of strings and converts them to integers or floating point numbers if possible. Doing this for integers is pretty easy if element.isdigit(): newelement = int(element) Floating point numbers are more difficult. Right now I'm using partition('.') to split the string and checking to make sure that one or both sides are digits.
asked Feb 21 Mashhoodch 13k points
0 votes
1 answer 35 views
35 views asked Oct 23, 2020 Shaad Sh 800 points
0 votes
1 answer 9 views
Problem: I have this python program that adds strings to integers. I get this error: Python: TypeError: cannot concatenate 'str' and 'int' objects How can I add strings to integers?
asked Mar 31 ummesalma 29.2k points
0 votes
1 answer 5 views
Problem Anyone know how do i concatenate string and int in c++
asked Apr 10 Subhendu 4.5k points
1 vote
1 answer 52 views
Problem: Being a newbie in C++ programming, I wonder if I can concatenate an integer type and a string together! As I can concatenate two string, in the same way, is it possible to concatenate two different data types? I am in a certain condition right now and I ... ; and the integer is “7” I want to bind them together and display it as: Bond7 Thanks, guys. I appreciate your concern.
asked May 19, 2020 adamSw 11.3k points
0 votes
1 answer 28 views
Problem: I'm playing with both learning python and trying to get github issues into a readable form. Using the advice on How can I convert JSON to CSV? I came up with this: import json import csv f=open('issues.json') data = json.load(f) f.close() f=open("issues.csv" ... item["labels"], item["state"]]) Where "issues.json" is the json file containing my github issues. When I try to run that, I get
asked Feb 15 Mashhoodch 13k points
1 vote
1 answer 17 views
Problem: How to convert a string to int c++ ?
asked Mar 6 Raj Tyagi 15.6k points
0 votes
1 answer 18 views
asked Jan 13 alexh 2.6k points
0 votes
1 answer 62 views
62 views asked Oct 27, 2020 xgtx 320 points
0 votes
1 answer 23 views
23 views asked Oct 16, 2020 SapperIt 1.2k points