Workings for addition calculator is not showing [duplicate] - python

This question already has answers here:
How do I put a variable’s value inside a string (interpolate it into the string)?
(9 answers)
Closed 1 year ago.
print ("Naomi's Calculator!")
print("Addition")
value_1= 10
value_2= 15
working= (value_1 "+" value_2)
print(working)
result=(value_1+value_2)
print(result)
working variable is wrong, i want the result to be like 10+15

value_1 and value_2 are int, you need to convert them in string if you want to see that output for working variable.
working = (str(value_1)+"+" +str(value_2))

Related

what does python think about B > A [duplicate]

This question already has answers here:
How are strings compared?
(7 answers)
Closed 1 year ago.
comparison of letter of alphabet
if "b" > "a":
print("greater")
is python going to evaluate them in order they appear in alphabet?
what if i evaluate a letter like a with a number?
will it be according to ASCII?
Yes.
Here are a few examples:
And for your convenience, the ASCII table:

How to convert a string, with functions inside, into a executable code in Python? [duplicate]

This question already has answers here:
How do I execute a string containing Python code in Python?
(14 answers)
Closed 2 years ago.
I have a .txt file that has the following text:
"np.sqrt(2)**2"
I can't get the answer to this mathematical equation because is a string, does anyone know how to convert that text to code (In python)? So when executing the script I will have the following output:
[In] np.sqrt(2)**2
[Out] 2
You can use the eval() method.
The return value is the result of the evaluated expression.
>>> x = 1
>>> eval('x + 1')
2
>>> eval('x')
1

Time comparison in python if it's in str format [duplicate]

This question already has answers here:
Comparing two timestamp strings in Python
(2 answers)
Convert string "Jun 1 2005 1:33PM" into datetime
(26 answers)
Closed 2 years ago.
I have two different values. One value(A) is 2020-03-06T10:00:00+05:30 and another one(B) is 2020-03-03 14:04:02. These two are in str formats. Now I have to compare these two different values as date.If the 'A' is greater than 'B' I have return 'True'
The method I have tired is
if A>B:
return True
else:
return False
What is happening is if it's greater or smaller it's always going to if statement only.
I am getting A & B from differnet sources and it's in the same format which I have given above.

How to add / between spaces in a date [duplicate]

This question already has answers here:
Replacing instances of a character in a string
(17 answers)
Closed 4 years ago.
How can I take a string that returns it in a list with " / " between them, like dates.
for example
Taking 5,11,2013 and the output be 5/11/2013
Use str.replace() ?
date = '11,12,2019'
print(date.replace(',', '-'))
>> 11-12-2019

Python 3 - convert mathematical action to integer [duplicate]

This question already has answers here:
Math operations from string [duplicate]
(8 answers)
Closed 6 years ago.
I have a string with a formula 5 - 3, and I need to get the result in integer. How could I do that?
use eval function:
eval("5 - 3") # 2
test = "5-3"
print(eval(test))
Gives 2

Categories

Resources