473,386 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Python Help

2
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.

Tasks

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:
eyas
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
CONGRATULATIONS! You guess it!

Thanks for playing

Or
rsnwae
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 1754
dazzler
75
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
bvdet
2,851 Expert Mod 2GB
Dew,

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)
  3.  
  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)
  3.  
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)
  4.  
  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
Dew
2
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

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

Similar topics

0
by: python-help-bounces | last post by:
Your message for python-help@python.org, the Python programming language assistance line, has been received and is being delivered. This automated response is sent to those of you new to...
3
by: stuart_white_ | last post by:
I've just upgraded from Python 2.3.3 to Python 2.4.2, and, although the new version of Python seems to be running correctly, I can't seem access the help from the interpreter. On Python 2.3.3...
32
by: siggi | last post by:
@Ben Sizer Hi Ben, in January I received your message re Pygame and Python 2.5: As a Python (and programming ) newbie allow me a - certainly naive - question:
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.