0
If I do this, a%b == 0, how can I store the value of a to another variable?
10 Answers
+ 2
Another_variable = a
Is it not working?
Pls add more clarification to question..
Can you show the code sample?
+ 2
f"{i}{mid_price}{j}"
Is an f-string
It is used to format a string It is equivalent to;
"{}{}{}".format(i, mid_price, j)
Or
str(i) + mid_price + str(j)
It's just a shorter way to do the multiple lines you have that accomplish the same thing, using less variables.
The the result of the new String is passed to the int() function
+ 1
Where is a assigned?
Can you show your code snippet?
+ 1
If you want to store the boolean value of this expression you can just enclose the expression in () and assign it to a variable :
c = (a%b==0)
If you want a 1 or 0 as response, pass it to int() function :
c = int(a%b==0)
+ 1
Is python need variable type declaration...?
Why are you using return a in loop..?
It has syntax errors..
I tried to remove all I and it giving output.. Are you trying same or something else.. idk. check this code? @Dan Honorio
mid_price = 1283
count = 31
for i in range (1,10):
plsfrstdgt = str(i) +str( mid_price
)
for j in range (0,10):
plslstdgt = plsfrstdgt + str(j)
fnlPrice = int(plslstdgt)
price_per_choco = fnlPrice//count
if fnlPrice % count == 0:
store=fnlPrice
print(store, price_per_choco
)
else:
print(store, price_per_choco
, "Impossible")
#added values in else part for clarity only, you can remove.
+ 1
Can you explain what this means ChaoticDawg? int(f"{i}{mid_price}{j}")
+ 1
Thank youđ
0
Code snippet:
str mid_price = 1283
int count = 31
for i in range (1,10):
plsfrstdgt = str(i) + mid_price
for j in range (0,10):
plslstdgt = plsfrstdgt + str(j)
fnlPrice = int(plslstdgt)
price_per_choco = fnlPrice//count
if fnlPrice % count == 0:
store=fnlPrice
return store, price_per_choco
else:
return "Impossible"
What I am trying to do here is I am trying to find the greatest value for fnlPrice that is divisible by my count. To do this, i thought of storing the values of fnlPrice that is divisible by count to the store variable until I find the greatest value for fnlPrice. The mid_price and count are just example inputs. the return impossible part means that if the possible values of fnlPrice is not divisible by count then I just return "impossible" on the command prompt
0
Thank you. I will try this