469,358 Members | 1,588 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

Python Help

Hello, iam new to programming, and ive been given a task in my Uni to complete certain exercises but i found it very difficulty to solve them. I was wandering if there is someone who can help me solve this problems. I cant tell u how much i will be gratefull if someone can help me. Please if anyone knows how to solve certain task reply to me.Thanks to all in advance.


1. Your are going to a restaurant where the tip is expected to be 15% of the total bill. Write a function that will calculate the tip and the total amount payable, given the bill amount. The output of your program should be formatted so that the amounts are preceded by a $ and are rounded to 2 decimal places. They should be printed as below.
For example if the function was called with the value of $100, the output should be:

Bill: $100.00
Tip: $ 15.00
Total Amount $115.00

2. The price of a car consists of its base price and a number of charges. Some are percentages of the base price, others are a flat rate. Using the table below, write a function that calculates the total price of a car when given the base price. The function should print out a summary of all the charges and the total price
Sales tax 10%
Commission 5%
Dealer Fee 15%
Licence Fee $100.00
Detailing $150.00
Roadworthy $ 50.00

Sample output:
Base Price $ 10000.00
Tax $ 1000.00
Commission $ 500.00
Deale $ 1500.00
Licence $ 100.00
Detailing $ 150.00
Roadworthy $ 50.00

Total Cost $ 13300.00

3. Write a function that simulates a fortune cookie. The program should display one of at least five unique fortunes at random each time it is run.

4. Write a function that plays the “Guess My Number”. It should randomly select a number between 1 and 100 and invite the user to guess the number. The program should allow the user 7 guesses, and tell the user if the number is higher or lower than their guess. If the user guesses the number the game should print a congratulatory message and terminate. If the user cannot guess the number, then the game should print a message to this effect, tell the user what the number was, and terminate

5. Write a function that jumbles a word and then asks the user to guess the word. The function should have a list of words it can pick randomly from. It should then jumble that word, print the jumbled word and ask the use to guess the correct word. The program should keep asking the user to guess until they either enter the correct word, or press return with no guess entered. The program should either print a message congratulating the user on guessing the correct word, or commiserating and giving them the correct word.

An example of the output could be:
Guess the word (return to quit): yese
Sorry, that's not it
Your guess(return to quit): yeas
Sorry, that's not it
Your guess(return to quit): easy

Thanks for playing

Guess the word (return to quit): runaway
Sorry, that's not it
Your guess(return to quit):
Bad luck, the word you were looking for is 'answer'

Thanks for playing

6. Write a program that creates a menu. The program should give the user a list of numbered options, and accept a number as the user’s choice. The program should run until the user chooses the exit number. Incorporate all the functions you have written above into the menu program so that the user can choose to run them using the menu. The program should give the user an error message if they choose an incorrect number.

The menu program should prompt the user for the input required for any function that requires input and pass that input into the functions.

Sample output

********* MENU **************
1 Tipping Calculation
2 Car Price Calculation
3 Fortune Cookie
4 Guess My Number Game
5 Word Jumble Game
6 Exit Program

What would you like to do: 8
Incorrect choice, try again

********* MENU **************
1 Tipping Calculation
2 Car Price Calculation
3 Fortune Cookie
4 Guess My Number Game
5 Word Jumble Game
6 Exit Program

What would you like to do: 6
Thank you for using this program
Bye Bye!
Jan 8 '08 #1
3 1528
can you be more specific at where are you having problems? and maybe show us what have you tried to do so far...
Jan 8 '08 #2
2,851 Expert Mod 2GB

We cannot do your homework for you! I will give you some hints for your problem #1. Following is a function that returns a formatted string given a floating point number:
Expand|Select|Wrap|Line Numbers
  1. def format_number(num):
  2.     return 'Formatted number: %0.2f' % (num)
  4. print format_number(10)
The following will return the total bill after calculating the tax and adding it to the price:
Expand|Select|Wrap|Line Numbers
  1. def calc_bill(num, tax=7.75):
  2.     return num + num*(tax/100.0)
Test the functions and show output:
Expand|Select|Wrap|Line Numbers
  1. print format_number(10)
  2. print calc_bill(150, 15)
  3. print calc_bill(150)
  5. >>> Formatted number: 10.00
  6. 172.5
  7. 161.625
  8. >>> 
I hope these examples will help you find solutions to your homework.
Jan 8 '08 #3
Thanx alot for the reply and the help, This is my first time doing programming and i found it very difficult, i only did very little bit of java before, but this python thing i cant seem to get it and they dont give us the proper understanding in Uni. Thanx again guys
Jan 9 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by python-help-bounces | last post: by
3 posts views Thread by stuart_white_ | last post: by
32 posts views Thread by siggi | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.