I am unable to perform the following exercise in python

Asked

Viewed 1,656 times

1

I am unable to perform the following exercise in python:

João Papo-de-Pescador, a good man, bought a microcomputer to control the daily income of his work. Every time he brings a weight of fish greater than that established by the fishing regulation of the state of São Paulo (50 kilos) must pay a fine of R $ 4,00 per kilo surplus. João needs you to do a program that reads the weight variable (fish weight) and calculates the excess. Write in the variable excess the amount of kilos beyond the limit and the variable fine the amount of the fine that John should pay. Print program data with appropriate messages.

Here’s what I tried:

pesos = input('Digite o numero de quilos q vc pegou:')

if pesos > 50:
    pesos -= 50
    excesso = pesos
    multa = excesso * 4

    print 'Total da multa: ' + str(multa)
else:
    print 'Não teve excesso'
    1. Read the weight. 2. If the value is greater than 50 kilos, subtract 50 to find the excess and store it in the "excess" variable, or otherwise assign zero to that variable. 3. Multiply "excess" by 4 and store this in the variable "fine".
  • And thanks bro I’ll do it

  • Victor has a way to fix my program? I think I did something wrong

  • Put it here. Edit the question.

  • ok put there

2 answers

5


You can simplify your code a little bit and don’t forget to show the excess too, in addition to the fine:

pesos = int(input('Digite o número de quilos que você pegou:'))

if pesos > 50:
    excesso = pesos - 50
    multa = excesso * 4

    print 'Total do excesso: ' + str(excesso)
    print 'Total da multa: ' + str(multa)
else:
    print 'Não teve excesso'
  • But what I did was right?

  • @Twz3xc21sadhack Essentially yes.

  • ok very obd pq I was thinking that part of the fine was wrong, but n was right agr I will continue with the exercises vlw ai

  • It may be worth noting that this code will only work in Python 2. In Python 3 the return of input is always a string, which would create error by comparing it to an integer.

  • @Andersoncarloswoss Corrected.

0

the code can be so, more summarized and using . format instead of summing the strings

pesos = input('Digite o numero de quilos q vc pegou:')
if pesos > 50:
    multa = (pesos - 50) * 4
    print ('Total da multa: {}'.format(multa))
else:
    print ('Não teve excesso')

Browser other questions tagged

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