Class 5 – Friday, January 26
It's all about you
Show understanding — Put it altogether now — Yes you all can do
Look both ways
Form
- Help improve CS 1112
Agenda
- Demontrate your own chresthomatics abilities by solving and submiting problem solutions before the end of class.
Galleries
- Nothing but the truth
What was meant to be past examples
- Uses the built-in cast functions
int()
andfloat()
to convert numeric strings into the numbers they represent.
- The final version of the program shows the two casts using built-in functions
int()
andfloat()
to convert the supplied string-based inputs into numerics.
- Introduces the string member function
split()
. Its called a member because every string can be called upon to produce a split up version of itself. The value of asplit()
invocation is the list of substrings (words) that make up the string being told tosplit()
. The function is handy for breaking up user input into its individual parts.
- The final version of the program shows that every string has a member function for inspecting itself. The
split()
function hands back the list of words that make up the string.
- Shows the proper way of converting the splitting of a string made up of numberic characters into individual numbers.
Homework requirement
- A numeric value display must be from the value of a variable; i.e., there will never be arithmetic calculations within a
print()
statement.
- All variables should be named indicating their purpose/usage.
- Always end each prompt with a space; e.g.,
input( 'What is something you consume daily?: ' )
Homework warning
- The testing of your programs will use inputs different from those shown in problem discussion.
In-class homework requirements
- Demonstrate to a classmate that you have met the problem specifications. Identify those person(s) as part of the header comments for your programs.
- Ensure your checkers have also been successfully checked out by somebody(s).
Program seconds.py
- Complete the program so that it determines and displays the number of seconds spent in CS 1112 this semester. A correct solution will print out the following and nothing else.
CS 1112: from 0 to programmer in 189000 seconds.
-
Requirements
- Update the header comments to name you as the program developer along with the email ID of your assistant.
- The only change in your code will be for the initialization expression for variable
seconds_of_1112
. The expression will be a product of three values, with none of the values being literals.
- Your assistant is responsible for your solution being correct.
-
Requirements
- My automatic grading tool will check that only lines 4, 5, 7, and 25 have been changed.
Program complimenter.py
- For a single user-supplied integer age, print out a tasteful compliment based on the supplied age.
-
Requirements
- The faux (complimentary) age is the user-supplied age minus five years.
- The faux age is to be integer.
- The program does not attempt to get more than one input from the user.
-
Three different program runs
- The above header means what it literally says. The below boxes each show a different program run; i.e., your program is to perform single age calculation each time it is run.
Enter your age: 19
You don’t even look 14
Enter your age: 111
You don’t even look 106
Enter your age: 20
You don’t even look 15
-
Suggested code outline
- Prompt user to supply an age
- Convert user reply to integer
- Compute supposed age
- Print the result of the computation
Program dateable.py
- For a single user-supplied age, tell them how old a person must be to have dating be acceptable according to the following folk rule:
- You should only date someone who is at least seven years older than than half your age.
For example, an 18 year old needs to date somebody at least 16 year's old (i.e., 7 + ( 18 / 2 ) ).
-
Requirements
- The dateable age is to be calculated by using the above folk rule.
- Use separate variables for storing the user-supplied and dateable ages.
- The displayed dateable age is to be integer.
-
Three different program runs
Enter your age (integer): 19
19 year olds should date somebody who is at least 16 years old
Enter your age (integer): 22
22 year olds should date somebody who is at least 18 years old
Enter your age (integer): 88
88 year olds should date somebody who is at least 51 years old
-
Suggested code outline
- Prompt user to supply an integer age
- Convert user reply to integer
- Compute minimum age according to dateability formula
- Print the result of the computation
To do list
- Ensure familarity by reading about Python variables, assignment, and input
Warning: fopen(/l/cs1112/public_html/defs/htm/181-trailer): Failed to open stream: No such file or directory in /l/cs1112/public_html/defs/php/read.php on line 5
Unable to open file!