|
CMPT 120: Lab 5
Write a function that takes one string argument as input. The function should return True if the string is more than half spaces, and false otherwise. Write a program that uses this function that will ask the user to input one string. It will then inform the user if the string is mostly spaces.
Enter a string: 1    2
The string you entered is more than half spaces.
Enter a string: hello world
The string you entered is not more than half spaces.
For the following parts of the lab you will need to use Python's documentation to understand the functions/modules that you'll need to use.
Write a Python program that prints out the current weekday and time like this :
Saturday, 04:35 PM
The time module contains a function strftime (“string format time”) that will format the current time. This statement will print the current time in a different format; get it working first. Then, use the online documentation to get the format as above.
print time.strftime("%b %d, %H:%M")
[Note: do not name the file time.py. If you do, it will confuse the import time statement—it will try to import the file you just created, not the time module that you need.]
Create a Python program that simulates rolling dice. These are standard dice; when rolled, they randomly show a number from 1 to 6, each with equal probability.
The random module contains functions that generate random values. In this problem, you need random integers from 1 to 6. When the program is run, it should look like this:
How many dice? 3
Die 1: 1
Die 2: 5
Die 3: 3
Chris Schmidt, last updated June 19, 2007 |