Python Forum
Task that i can't pass
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Task that i can't pass
#1
Hello. I am learning Python using pythontutor.ru website. There a task where i must write a program about bank deposit and it's profit 1 year later. I wrote a code, it gives right answer to all examples except 1. What can i do to make it right?

My code:
p = int(input())
x = int(input())
y = int(input())
kopeiki = ((p / 100) + 1) * ((x * 100) + y)
answer_rubles = (kopeiki // 100)
answer_kopeiki = int(kopeiki % 100)
print(answer_rubles, answer_kopeiki)
Wrong answer: https://i.postimg.cc/pV1jxKYD/image.png
Link to a task: https://pythontutor.ru/lessons/int_and_f.../percents/

Thanks for reading.
Reply
#2
Try this perhaps
r, k = divmod((100 + p) * (100 * x + y), 100)
Reply
#3
Gribouillis
Thank you for an answer. I really appreciate it.

But i am not allowed to use it.
Pythontutor is a course and (i think) we must use features that we were taught to use.
As long as i remember, there is no divmod.
We learnt only "if", "else", "*, /, //, %, **, +, -" and some "math" features that are listed here: https://pythontutor.ru/lessons/int_and_float/

Also, a task in English:

P - bank % for 1 year deposit
x - dollars
y - cents
How many dollars and cents are in a bank deposit after 1 year?


We must give an answer in this format: dollars, cents

"rubles" is a russian currency and "kopeiki" is russian "cents". There are 100 "kopeiki" in 1 ruble.

P.S. I will learn what "divmod" is.
Reply
#4
If you wrote your own divmod it would look like this:
def mydivmod(a, b):
    return (a // b, a % b)
Reply
#5
Looking at your answer and the right answer, you are off by one kopek, low, on that one example only. Suggest this is a rounding error and that you are supposed to round up in that case?
Reply
#6
(Aug-20-2020, 11:40 AM)jefsummers Wrote: Looking at your answer and the right answer, you are off by one kopek, low, on that one example only. Suggest this is a rounding error and that you are supposed to round up in that case?

If i will change the formula - it will affect other answers, and they will become wrong
Reply
#7
p = int(input())
x = int(input())
y = int(input())
all = x * 100 + y
all1 = all + ((p / 100) * all)
rubles = all1 // 100
kopeiki = all1 % 100 // 1
print(rubles, kopeiki)
This is the answer.
I didn't even know till now that you can write formulas without "int" or "float" or other.
And those "int" and "float" were messing the result all the way.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pass an object to a class, then make an object of it and pass again TomasAm 11 4,769 Nov-09-2020, 04:47 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020