0

If I do this, a%b == 0, how can I store the value of a to another variable?

3rd Jun 2021, 6:54 PM
Dan
Dan - avatar
10 Antworten
+ 2
Another_variable = a Is it not working? Pls add more clarification to question.. Can you show the code sample?
3rd Jun 2021, 7:01 PM
Jayakrishna 🇮🇳
+ 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
3rd Jun 2021, 8:37 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Where is a assigned? Can you show your code snippet?
3rd Jun 2021, 7:06 PM
Lisa
Lisa - avatar
+ 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)
3rd Jun 2021, 7:10 PM
Ervis Meta
Ervis Meta - avatar
+ 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.
3rd Jun 2021, 7:49 PM
Jayakrishna 🇮🇳
3rd Jun 2021, 7:57 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Can you explain what this means ChaoticDawg? int(f"{i}{mid_price}{j}")
3rd Jun 2021, 8:31 PM
Dan
Dan - avatar
+ 1
Thank you🙂
3rd Jun 2021, 8:38 PM
Dan
Dan - avatar
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
3rd Jun 2021, 7:19 PM
Dan
Dan - avatar
0
Thank you. I will try this
3rd Jun 2021, 7:57 PM
Dan
Dan - avatar