![]() |
|
[Python] new to python. Into class question - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] new to python. Into class question (/showthread.php?tid=5701153) Pages: Pages
1
2
|
new to python. Into class question - Truhmp - Aug 22, 2017 So my first day of intro to programming we are going to be learning python which im glad. I was able to easily do the first two assignments with breeze since my instructor was there to teach me about what was needed in those. My first day was durring the eclipse and everyone wanted to go outside so class was called early and I was not taught anything about how to do this next Exercise. If someone can simply just show me what they would do using python 3 I can easily understand why you did it and that will be enough for me. Write a program that prints the balance of an account after the first, second and third year. The account has an initial balance of $1000 and earns 5 percent interest. Please can someone help me out, Ive spent 6 hours going through my textbook and they do not show me this either. Online has a few option for using java but im using python 3. Thank you for your time. EDIT: This is what ive came up with so far but still failing at figuring out how to calculate after Year One: and so on. #####Account Balance##### print(" Account Balance after 3 years and earning 5 percent interest"); print() print() print("Year One:")+(1000*1.05) print(1000*1.05*1.05); print(1000*1.05*1.05*1.05); print() print() input() How do I make it look like Year One: 1050, then I can do the rest. * - Bαker - Aug 22, 2017 Why not do something like this, (Quick throw together on mobile) A = $1000 B = A .05 C = B .05 - - - Obviously you'd need to actually code it up but maybe this would help. (FYI I am not a python guy, im a front dev type guy so this is just a basic example) * - Lukos1234 - Aug 22, 2017 I'm new to python but try this : PHP Code Here's a much simpler one : PHP Code which could give us: with an interest of 5 % and an initial balance of $1000 for year 1 your balance is $1050.0 for year 2 your balance is $1102.5 for year 3 your balance is $1157.625 # Just a simple function that asks for years , interest and beginning balance in account. # interest accumulates each year , if each month I can rewrite the function. #if anyone got the solution for converting input result into integer directly please help. * - Vana - Aug 22, 2017 I'd write a function: PHP Code And just call it for each print: PHP Code You need to use the "format" function to add it to the strings as you can't directly concentrate numbers and strings in Python. And if you need a variable number of years... PHP Code * - Lukos1234 - Aug 22, 2017 (Aug 22, 2017 09:03 PM)Vana Wrote: years = input("Years to show: ") Does this work even without converting the variable "years" to int ? because I read that input function gives you a string. * - Vana - Aug 22, 2017 (Aug 22, 2017 09:15 PM)Lukos1234 Wrote: Does this work even without converting the variable "years" to int ? because I read that input function gives you a string. You're right, in Python 2.x `input()`will interpret it as an int but not in Python 3. Fixed my code. * - Retribute - Aug 23, 2017 Using OOP is much cleaner and easy to read. PHP Code Output: PHP Code * - datguy.dev - Aug 23, 2017 I think you have enough here to complete this task. But consider what data type would best fit the role for USD and how it should be rounded. When multiplying, if you round fractions of a penny off an interest rate, then that could be considered fraud. You may want to try and not overthink assignments. Consider the code expected for you is beginner-level. Save yourself the time. I over complicated my code in school trying to impress, but it really did nothing for me except for being investigated for plagiarism. No one was ever impressed. Instead, just do what the assignment asks perfectly. * - Truhmp - Aug 23, 2017 Wow thank you everyone for the responses. I was able to complete the exercise with this information. This is alot of fun, although im not doing anything too complex yet im having alot of fun with the basics. * - Lukos1234 - Aug 24, 2017 (Aug 23, 2017 07:42 PM).bLunts Wrote: Wow thank you everyone for the responses. I was able to complete the exercise with this information. This is alot of fun, although im not doing anything too complex yet im having alot of fun with the basics. wait till you get to files handling :D * - vorticalbox - Aug 25, 2017 (Aug 24, 2017 12:48 AM)Lukos1234 Wrote: wait till you get to files handling :D Files are easy PHP Code Wrote on my phone so spacing will be wrong. * - Allelujah - Aug 25, 2017 Simple solution: PHP Code * - vorticalbox - Aug 25, 2017 (Aug 25, 2017 02:44 PM)Allelujah Wrote: Simple solution: Why didn't you just do this in a for loop updating a variable? Would say you writing it out three times. Also why are you making it a float then converting to a string? It's already a float. * - (╯°□°)╯︵ ┻━━┻ - Aug 25, 2017 Code def future_value(principle, interest, years = 1):* - Allelujah - Aug 25, 2017 (Aug 25, 2017 03:17 PM)vorticalbox Wrote: Why didn't you just do this in a for loop updating a variable? Would say you writing it out three times. Also why are you making it a float then converting to a string? It's already a float. Because I'm still learning and I figure he is too from his post. Thanks for your input. I actually thought about a loop after I had posted. |