Subject Computer Science Python Programming

Question

Q1:Write a program in python to calculate how many years does it take for you to trash your car, if you start your car value of 20000 and each year you pay 5% of your car value (i.e., 20000*5%) to repair your car. Hint, we assume if the car value is less than the repair fee, you should trash your car.

Q2: Write a program in python for an elementary student to help me practice arithmetic addition.
1. random generate two numbers from 0 to 100, named as a and b
2. calculate a+b and save as correct.
3. catch the starting time
4. ask a user to input their result and save as answer.
5. catch the ending time
6. while the answer is not correct or the calculation time is longer than 10 seconds, show the correct answer and then repeat 1-5.
7. print on the console "You are good!"

Q3: Write a program in python that asks users to enter their name and age. While their name is not "Nobody", the program displays an information box showing users’ name and age on the information box

Q4: Write a Python function printGreetings to print out "Hello" and "Goodbye" for all 100 students using "while" statement. The output is as follows:
Hello, Student1!

Goodbye, Student1!

Hello, Student2
!
Goodbye, Student2!

Hello, Student3!

Goodbye, Student3!

...

Hello, Student98!

Goodbye, Student98!

Hello, Student99!

Goodbye, Student99
!
Hello, Student100!

Goodbye, Student100!

Q5: Ask the user to enter the value of the expression   8 + 7 * 5 / 2 - 6.   
To allow them to enter floats, we will use requestNumber() as opposed to requestInteger() for the user's answer.
In order to make the prompt more readable, we should split it into two lines in the requestNumber() dialog box. We use the character sequence \n to insert a carriage return in a string, e.g., "What is the value of the Python expression \n 8 + 7 * 5 / 2 - 6 ?"
Calculate the correct response and store it as the variable correct.
Check the user's response using while loop such that:
while the user's response is not the correct answer
If the user's response is less than the correct answer, print "Too low!" to the console. It does not matter at this point if they entered 5 or 5.5, for example--just that it's less than the correct answer.
Else, if the user's response is greater than the correct answer and not equal to incorrect, print "Too high!" to the console.
Else, if the user’s response is incorrect, print “incorrect!”
Ask users calculate it again!
If the user's response is equal to the correct answer, print "Correct!" to the console.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

"""
Q1: Write a program in python to calculate how many years does it take for you
to trash your car, if you start your car value of 20000 and each year you pay
5% of your car value (i.e., 20000*5%) to repair your car. Hint, we assume if
the car value is less than the repair fee, you should trash your car.
"""
def main():
    fee = 0
    year = 0
    while fee <= 20000:
       year += 1
       fee += 20000*0.05
    print "Years to trash your car is: " + str(year) + " years."
   
main()...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Minesweeper Game in Python
Homework Solution
$100.00
Minesweeper
Game Development
Python
Programming
Classes
Objects
Entertainment
IF-Conditions
Functions
Loops
Random Values
Python Programming Problems
Homework Solution
$60.00
Computer Science
Python
Programming
Characters
Text
Strings
Variables
Occurrences
Lines
Input
Output
Lowercase Letters
Capital Letters
Parsing
Absolute Value
Lists
Elements
Encoder
Decoder
Parameters
Presidential Election Problems in Python
Homework Solution
$8.00
Computer Science
Python Programming
Presidential Elections
Votes
Classes
Students
Patterns
Candidates
Algorithms
Tank Clash in Python
Homework Solution
$75.00
Computer Science
Programming
Python
Tank Clash
Algorithms
Variables
Statements
Loops
Characteristics
Numbers
Damage
Protection
Accuracy
Morale
Targets
Calculations
Data Structures
Lists
Tuples
Word Counter
Homework Solution
$35.00
Computer
Science
Python
Programming
Word
Counter
Frequency
Usage
Get help from a qualified tutor
Live Chats