• Register
1 vote
69 views

Problem:

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

Answer:

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 14 views
14 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 4 days ago Mashhoodch 9.1k points
0 votes
1 answer 29 views
29 views asked Oct 23, 2020 Shaad Sh 800 points
0 votes
1 answer 3 views
3 views
Problem: I searched around but i couldn't find any post to help me fix this problem, I found similar but i couldn't find any thing addressing this alone anyway. Here's the the problem I have, I'm trying to have a python script search a text file, the text file has numbers in a ... output is every thing containing a 2 and a 0, so i get 220 foo 200 bar etc. How can i fix this so it just find "20"
asked 5 days ago Mashhoodch 9.1k points
0 votes
1 answer 7 views
7 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 9.1k points
1 vote
1 answer 44 views
44 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 13 views
13 views
Problem: How can I convert a String to an int in Java? My String contains only numbers, and I want to return the number it represents. For example, given the string "1234" the result should be the number 1234.
asked Feb 3 Ali 4.4k points
0 votes
1 answer 5 views
5 views
Problem
asked Jan 13 alexh 2.4k points
0 votes
1 answer 51 views
51 views asked Oct 27, 2020 xgtx 320 points
0 votes
1 answer 18 views
18 views asked Oct 16, 2020 SapperIt 1.2k points
1 vote
1 answer 37 views
37 views
Problem: I am beginner in pyhton prgramming language, I tried to convert string array to int array using python so I wrote a code which contains- testing_list = ['4', '2', '3', '9', '5'] And my code is: testing_list = ['4', '2', '3', '9', '5 ... list is : str(testing_list) Converted list is : str(testing_list) why am I not getting the converted result and what is the way to get the acurate result?
asked Mar 29, 2020 LizzyM 6.1k points