Question

For this program you will convert knuts to sickles and galleons (Yes, Harry Potter here...). Your...

For this program you will convert knuts to sickles and galleons (Yes, Harry Potter here...). Your program should first prompt for the the number of knuts. Then perform the calculations: there are 29 knuts in one sickle and 17 sickles in one galleon. Print the results from the calculations. Be sure to print only non-zero values--that means if there are not enough knuts to be one sickle, then (as an example), "0 sickles" should not be printed.

how can i fix and improve this program

total_knut_int=int(input("enter the number of knuts:"))
knut_int = 1
sickle_int = 29
gallions_int = 17*29

num_galleon =0
num_sickle = 0

while (total_knut_int < 0):
print("enter a positive number:")
if total_knut_int > 0:
if total_knut_int > 0:
num-galleon,rem = divmod(total_knut_int,galleon_int)
if rem > 0:
num_sickles, rem = divmod(rem,sicke_int)
if num_galleon !=0:
print("number of galleons:", num_galleon)   
if num_sickle !=0:
print("number of sickles:", num_sickle)
if rem !=0:
print ("remainder of knuts:" , rem)
else:
print("imput is not more than zero")

0 0
Add a comment Improve this question Transcribed image text
Answer #1
total_knut_int=int(input("enter the number of knuts:"))
knut_int = 1
sickle_int = 29
gallions_int = 17*29
num_galleon =0
num_sickle = 0

while (total_knut_int < 0):
    print("enter a positive number:")
    total_knut_int = int(input("enter the number of knuts:"))

if total_knut_int > 0:
    num_galleon = total_knut_int // gallions_int
    total_knut_int = total_knut_int % gallions_int
    num_sickle = total_knut_int // sickle_int
    total_knut_int = total_knut_int % sickle_int
    if num_galleon != 0:
        print("number of galleons:", num_galleon)
    if num_sickle != 0:
        print("number of sickles:", num_sickle)
    if total_knut_int != 0:
        print("remainder of knuts:", total_knut_int)
else:
    print("imput is not more than zero")

Add a comment
Know the answer?
Add Answer to:
For this program you will convert knuts to sickles and galleons (Yes, Harry Potter here...). Your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For this program you will convert knuts to sickles and galleons (Yes, Harry Potter here...). Your...

    For this program you will convert knuts to sickles and galleons (Yes, Harry Potter here...). Your program should first prompt for the the number of knuts. Then perform the calculations: there are 29 knuts in one sickle and 17 sickles in one galleon. Print the results from the calculations. Be sure to print only non-zero values--that means if there are not enough knuts to be one sickle, then (as an example), "O sickles" should not be printed. You must use...

  • 1.Inspired by the Harry Potter books, where the valucs of the types of coins that are available a...

    1.Inspired by the Harry Potter books, where the valucs of the types of coins that are available are prime multiples of one another (17 Sickles in a Gallcon, and 29 Knuts in a Sickle), the dictator of a small nation decided that only three types of coins would have legal tender, all based on a unit called thc GSK Coins worth 5 GSK Coins worth 7 GSK. Coins worth 11 GSK a)Prove that there is no way to buy an...

  • Need help with creating conversion function checkout (num_hats, num_tels, num_creams): This function starts off knowing how...

    Need help with creating conversion function checkout (num_hats, num_tels, num_creams): This function starts off knowing how many Headless Hats, Boxing Telescopes, and Canary Creams we would like to purchase at Weasleys' Wizard Wheezes. You can just use those three parameters to calculate. (Assume they're all non-negative numbers). The prices are two galleons per Headless Hat, 12 sickles and 26 knuts per Boxing Telescope, and seven sickles per Canary Cream. Calculate and return the total price in knuts. In the wizarding...

  • Write a C++ program that computes the following series: sum = 1/firstPrime + 2/secondPrime+…..+1/nthPrime Your program...

    Write a C++ program that computes the following series: sum = 1/firstPrime + 2/secondPrime+…..+1/nthPrime Your program should prompt the user to enter a number n. The program will compute and display sum based on the series defined above. firstPrime: is 2 secondPrime: the first prime number after 2 thirdPrime: the third prime number …. nth prime: the nth prime number Your program must be organized as follows: int main() { //prompt the user to enter n //read n from the...

  • CSC 126 Arrays, Functions, & File 'O Part I Your program should prompt the user to...

    CSC 126 Arrays, Functions, & File 'O Part I Your program should prompt the user to calculate the total bill of a transaction at a Book store After the calculations have been performed, the program should output the result to the screen and save the output in a text file which can be later retrieved The program should work as follows: XYZ Book Store Sales Register This program calculates your total bill and generates a receipt for you. Please enter...

  • Write a program in c++ that generates a 100 random numbers between 1 and 1000 and...

    Write a program in c++ that generates a 100 random numbers between 1 and 1000 and writes them to a data file called "randNum.dat". Then re-open the file, read the 100 numbers, print them to the screen, and find and print the minimum and maximum values. Specifications: If your output or input file fails to open correctly, print an error message that either states: Output file failed to open Input file failed to open depending on whether the output or...

  • 1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The...

    1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The program should use the for loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, ... 50. If the user enters a zero or negative number, a message should be given and the program should not continue (see Sample Run...

  • Task 5.2 Numerical Analysis Using Nested Loops (13 pts) Consider the following program: void setup() {...

    Task 5.2 Numerical Analysis Using Nested Loops (13 pts) Consider the following program: void setup() { //Read a positive integer from the user //Your code starts here } Complete this program such that it calculates all prime numbers between 1 and the value that is assigned to variable num and outputs them on the screen. A prime number is a positive integer that has no other factors other than itself and 1. You should use a nested loop, i.e., write...

  • Change your C++ average temperatures program to: In a non range-based loop Prompt the user for...

    Change your C++ average temperatures program to: In a non range-based loop Prompt the user for 5 temperatures. Store them in an array called temperatures. Use a Range-Based loop to find the average. Print the average to the console using two decimals of precision. Do not use any magic numbers. #include<iostream> using namespace std; void averageTemperature() // function definition starts here {    float avg; // variable declaration    int num,sum=0,count=0; /* 'count' is the int accumulator for number of...

  • QUESTION 6 15 marks In this question you have to write a C++ program to convert...

    QUESTION 6 15 marks In this question you have to write a C++ program to convert a date from one format to another. You have to write a complete program consisting of amain () function and a function called convertDate(). The function receives a string of characters representing a date in American format, for example December 29, 1953. The function has to convert this date to the international format. For example: If the string December 29, 1953 is received, the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT