Sale of automated stamps (Python)

Asked

Viewed 92 times

-2

Good afternoon, sera could help me with a python problem?

I need:

(1) Calculate the amount of 50 and 20 cent stamps to be purchased by the user.

(2) Tip 2: To figure out how to calculate the number of stamps, always think about taking as many as possible of 50 stamps (analogous to the ink problem, but now it is not allowed to buy extra stamps, the value must be exact). So make a table with the prices of 10 in 10 cents, write for each case how many stamps are needed and try to find a pattern. For example, the largest amount of stamps of 50 for a cost of R $ 1,10 is 2, but then we can not fill the 10 cents missing. But it is possible to arrive at the exact value with a stamp of 50 less and 3 seals of 20. Following this example, what happens to the value of 1.60? and 2.10? 2,60? What is the relationship between these values and the seal of 50?

What I’ve done so far:

custo = round(100*float(input()))
while custo<70 or custo>620 or custo%10!=0:
    print('Preco invalido, refa?a a leitura do pacote.')
    custo = round(100*float(input()))
    selos_50 = custo//50
    selos = custo-(selos_50*50)/20
    if selos==0:
        selos_20 = custo//20
        selos = (custo-selos_50*20)/50
    else:
    print('Compre',selos_20,'selo(s) de R$ 0.50 e',selos_50,'selo(s) de R$ 0.20!')

while done was for validation of the entries. There I need in this print show how many Sevens of 20 and 50 have to use.

Do you think you can help?

1 answer

0

first divide the value by 0.5

selo_50 = custo / 0.5
resto_50 = custo % 0.5

Blz, but now it may be that the change cannot be divided by 0.2. example 1.10 split 0.5 = 2, remaining 0.1

In this case decrease a stamp of 50 and will remain another 0.5 in the example 0.1 + 0.5 = 0.6 which is divisible by 0.2

if ( resto_50 % 0.2 != 0 ):
  selo_50 -= 1
  resto_50 += 0.5

selo_20 = resto_50 / 0.2

Browser other questions tagged

You are not signed in. Login or sign up in order to post.