How to fix error when adding string to input variables? [duplicate] - python

This question already has answers here:
How do I append one string to another in Python?
(12 answers)
Closed 3 years ago.
.It says invalid syntax on the ' around the docx.
y = input ("lektion :")
print(y)
document.save(y.'docx')

Use this:
y = input ("lektion :")
print(y)
document.save(y + 'docx')

Related

5*2=55 not 10! Why? [duplicate]

This question already has answers here:
multiplication of two arguments in python [duplicate]
(6 answers)
Getting issue while trying to multiply string and integer [duplicate]
(2 answers)
Closed 3 months ago.
I want to output 5 * 2 = 10 but python output is 55!
How do I resolve this problem?
a = 0
b = 2
a = input("a? :") #(get 5 as input)
c = a * b
print (c)
This is my code.
when I input a number it repeat same number I entered two times insterd of showing multipiy it. What do I have to do to solve this?
a is a string,
so it will be
'5'*2='55'
if you want 10, you need to cast a to int.
a=int(input())
here is the link to document
https://docs.python.org/3/library/functions.html#input

The Code works right but there is something wrong [duplicate]

This question already has answers here:
Why is "None" printed after my function's output?
(7 answers)
Why is this printing 'None' in the output? [duplicate]
(2 answers)
Closed 1 year ago.
This is my code, when I run it gives me the right answer but also it gives me 'None':
My Code:
def art() :
a = input('enter a values')
b = eval(a)
print(b)
print(art())
Output:
enter a values3 + 4
7
None
Does anyone know why is that and how to remove it? Thank you.

String to Int in Python [duplicate]

This question already has answers here:
Why does map return a map object instead of a list in Python 3?
(4 answers)
Getting a map() to return a list in Python 3.x
(11 answers)
Closed 5 years ago.
How to Convert a string like '123' to int 1,2 and 3 so that I can perform 1+2+3. I am new to python. Can you please help me? I am not able to split the list. I don't think splitting the string will be of any use as there are no delimiters. Can you help me to understand how can this string elements be separated and treated as intergers?
x = "123"
s = 0
for a in x:
s = int(a) + s

Python - String and int variable concat followed by value substitution [duplicate]

This question already has answers here:
How do I create variable variables?
(17 answers)
Closed 6 years ago.
I have a list of variables in Python with below values.
I am trying to print the values of these variables in the following manner, but this is unsuccessful. Can someone please help with a solution ?
a1=1
a2=2
a3=3
for i in range(1,4):
temp="a"+str(i)
print(temp)
I want the output in 'temp' print the values(viz) 1,2,3 whereas the output seen are the variables (viz) a1,a2,a3
Try This:-
a1=1
a2=2
a3=3
for i in range(1,4):
temp="a"+str(i)
print locals()[temp]

How to convert str to hex via python [duplicate]

This question already has answers here:
Print a string as hexadecimal bytes
(13 answers)
Closed 7 years ago.
I want to convert string to a hex (decimal),
for example abc to 616263 and so on.
How do I do that?
I have tried:
x= input("Enter string")
x = int(x)
hex(x)
But it is not working.
maybe you are looking for something like:
x.encode("hex")

Categories