Python Lab Ex 5

seeders: 0
leechers: 0
Added on April 19, 2015 by 3sgknightin Other > Tutorials
Torrent verified.



Python Lab Ex 5 (Size: 4.52 KB)
 L5_E1.py1.19 KB
 L5_E2.py1.59 KB
 L5_E3.py1.73 KB


Description

L5.2 Exercises
Exercise L5.E1 - Develop a program that takes as input a series of positive integers and outputs
whether each is a prime. The program should terminate if a negative integer is given as the
input. A prime number is a number that is divisible by only one and itself. However one is not
considered a prime number. Execution of your program should produce something similar to
the following:

$ python prime.py
1
2
prime
3
prime
4
5
prime
-1



Exercise L5.E2 - Develop a program that takes as input a series of positive integers and outputs
whether each is a perfect number. The program should terminate if a negative integer is given
as the input. A perfect number is a number whose factors other than itself add up to itself.
Examples: 6 = 1 + 2 + 3, 28 = 1 + 2 + 4 + 7 +14

$ python perfectnumber.py
6
perfect
7
28
perfect
11
-1



Exercise L5.E3 - Develop a program to implement the "Guess the Number" game. In this game, the
program thinks of a random integer in the range [1, 20] and asks the user to guess it. The user
gets only four attempts, and for each wrong guess, the program will tell if the guess is too high
or too low. To win the game, the user has to correctly guess the number within four attempts.
You may include the "import random" line at the top of your program to use the "random"
module and then use the "random.randint()" function to generate the random integer.


Related Torrents

torrent name size seed leech

Sharing Widget


Download torrent
4.52 KB
seeders:0
leechers:0
Python Lab Ex 5