Python & OpenSesame Course @ BGU 2015 – Yoni Melman Home

advertisement
Python & OpenSesame Course @ BGU 2015 – Yoni Melman
Home Exercises
Basics
1. Build a tip calculator! Write the price of the meal in the variable meal_price. The tip
calculator should print the amount of tip needed for the meal (10%).
2. Ask the user for his/her name (use the raw_input() function). than print a greeting to the
user "Hello _____(user name), Welcome"
3. Collect a sentence from the user. Print the sentence in capital letters.
Python Standard Library
1. From the Python Standard library, find the module that deals with time and timing. Find
the function that presents the current time and date.
2. Print 100 random numbers from a Gaussian distribution with a mean 0 and SD 1
3. Write a program that waits 10 seconds then prints "I waited enough!"
4. Find the module and function that opens a website from a given link.
Loops
1. Create a program that prints all the odd numbers between 1 to 100 (1,3,5,7…).
2. Fibonacci sequence. The Fibonacci sequence is a sequence of numbers following a rule
observable here (1, 1, 2, 3, 5, 8, 13, 21…). Find the rule and write a program that
calculates the Fibonacci sequence and discover what the number that follows 89 is.
Turtle Drawings
1. Create a program that draws a spiral with Turtle.
2. Create a program that draws a circle from squares (shown in class)
Functions
1. Palindrome! A palindromic number is a number that is the same when presented
backwards, for example: 12321, 5005 etc. write a function that takes as input a number
and returns True if the number is a palindrome and False otherwise.
2. Create a program takes the user input. If the input is a digit between 0 and 9, use turtle
to draw this digit (use straight lines for simplicity). Write a function for each of the digits
(one(), two() etc..). After turtle draws a digit, ask for another user input and clear the
screen. If the input is 'esc', end the program.
More exercises
1. Understanding Yoda. Everybody knows that Yoda talks funny. Here you will find an
original quote from the famous Jedi. Sort the list to understand Yoda.
['04. Powerful', '01. you', '02. have', '03. become','07. the', '08. dark', '09. side', '05. I',
'06. sense', '10. in', '11. you.']
2. Create a program that prints the number of letters of the longest word in a sentence
(hint, use the split() method).
3. Create a program that flips a coin, which randomly lands on either "HEADS" or "TAILS".
Ask the user for his/her's bet. If the user was correct, give him fictional 100$, otherwise
ask him for 100$.
4. Write an ATM machine program, it should have the following features: 1. indication of
how much money you currently have, 2. ability to withdraw money (and change the
current amount), 3. ability to insert cash into the machine (add to the current amount).
Download