# This is a comment to describe the below program
#
# This program is being written for CS 111 for Assignment X
#
# Author: Your name here
# Date: Today's Date
#
def functionName ():
<nbsp> # place code here
<nbsp> # pay attention to indention! VERY IMPORTANT IN PYTHON!!!
<nbsp> # create and intialize variables first
<nbsp> # do any needed calculations
<nbsp> # print results
print ("Hello. Hope you have a good day.")You should also note that in python you can omit the parentheses to get the same result.
print "Hello. Hope you have a good day."To print out a number or the value of a variable, we place that information between the parenthesis. For example:
print (57)
print (number)We can print both some text and a value by placing both of these in between the parenthesis and separating them with a comma, such as:
name = "Bill"
print ("The name is", name )The comma will add 1 space character between the text and value stored in the variable.
number = 42
print ("The answer to the ultimate question is", number )The function str DOES require the use of parentheses. It is often better to over-parenthesize rather than under-parenthesize. Thus when given the option of having or NOT having parentheses, it is often better to use the parentheses. Also note that to print a blank line in the output (i.e. to skip a line), use print without the parenthesis or with a "empty text string" between the parenthesis..
print ("")Both produce the same result. You will notice that often the same result can be produced via different approaches. Instead of printing out multiple values by separating the values with a comma in the print statement, we can use the + operator and the str() function. However no extra space is added to the output. In most cases the extra space in no big deal (or even a good thing). So the above print statements could be rewritten as:
number = 42
print ("The answer to the ultimate question is " + str(number) )
As I was going to St. Ives,
I met a man with seven wives,
Every wife had seven sacks,
Every sack had seven cats,
Every cat had seven kits,
Kits, cats, sacks, wives,
How many were going to St. Ives?
You are required to use variables, multiplication and addition operations to calculate and determine the answers. For example:
#declaring variablesnumMan = 1 # determining the number of mennumWives = numMan * 7 # determining the number of wives
Just storing the value of 7 into the variable numWives is NOT enough for full credit for the assignment.
Submission of the Lab The lab must be submitted electronically to the Assignment Link for Lab 1 inside of Blackboard. You will only need to submit the python source code file (this is the ".py" file). You are to name your program file (and the class) using both your NET-ID and the Lab Number. Thus for Lab 1, if you NET-ID was ptroy4, your program should be named: ptroy4Lab1.pyprint ("The number of wives are:" , numWives)
Copyright 2016 The Board of Trustees of the University of Illinois.webmaster@cs.uic.edu |
WISEST Helping Women Faculty Advance Funded by NSF | ![]() | ![]() |