![]() |
|
Code with a language you don't know - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Coding (https://sinister.li/Forum-Coding--71) +--- Thread: Code with a language you don't know (/Thread-Code-with-a-language-you-don-t-know) |
RE: Code with a language you don't know - Vi-Sion - 07-16-2018 Dam python number system is kind off so annoying for some reason on every substraction they don't give me the supposed value. I've heard that using decimal will fix it tried but still with decimal not getting exact values. Any ideas ? Thats my code so far . Code: from decimal import *;
quarters=Decimal(0.25);
dimes=Decimal(0.1);
nickels=Decimal(0.05);
pennies=Decimal(0.01);
countQuarters=0;
countDimes=0;
countNickles=0;
countPennies=0;
userInput=Decimal(input("Amount of money"));
while(userInput!=0):
if(userInput>=quarters):
countQuarters+=1;
userInput=userInput-quarters;
print(userInput);
elif(userInput>=dimes):
countDimes+=1;
userInput=userInput-dimes;
print("hi2");
elif(userInput>=nickels):
countNickles+=1;
userInput=userInput-nickels;
print("hi3");
print(userInput);
elif(userInput>=pennies):
countPennies+=1;
userInput=userInput-pennies;
print ("hello");RE: Code with a language you don't know - Vi-Sion - 07-19-2018 Solution : Spoiler:Code: from decimal import *;
quarters=round(Decimal(0.25),2);
dimes=round(Decimal(0.1),2);
nickels=round(Decimal(0.05),2);
pennies=round(Decimal(0.01),2);
countQuarters=0;
countDimes=0;
countNickels=0;
countPennies=0;
userInput=round(Decimal(input("Amount of money")),2);
while(userInput!=0):
if(userInput>=quarters):
countQuarters+=1;
userInput=round(userInput-quarters,2);
elif(userInput>=dimes):
countDimes+=1;
userInput=round(userInput-dimes,2);
elif(userInput>=nickels):
countNickels+=1;
userInput=round(userInput-nickels,2);
elif(userInput>=pennies):
countPennies+=1;
userInput=round(userInput-pennies,2);
sumCount=countQuarters+countDimes+countNickels+countPennies;
print("the minimum amount of coins needed is ",sumCount," coins :",countQuarters," Quarters, ",countDimes," Dimes, ",countNickels," Nickels, ",countPennies," Pennies. ");If Anyone knows python pls let me know i have something to ask. Anyway the new exercise will be to write a function that checks if a String inputed by the user is a palindrome or no and prints the String is a palindrome if it is or the String isn't a palindrome if it isn't. Example: radar radar is a palindrome dog dog isn't a palindrome RE: Code with a language you don't know - Vi-Sion - 07-25-2018 Looks like you guys got bored from this game
|