TWiki
>
CS111 Web
>
CS111Spring2017
>
AssignmentsS17
>
Lab1s17
(2017-01-23, Main.troy)
(raw view)
E
dit
A
ttach
---++ CS 111 - Introduction to Computing, Spring 2017 ---++ Lab 1 For this assignment, we will write a simple Python program in the JES environment. You should look at the example program [[CodeS17][lect0119a.py ]]that was written in lecture on 1/19. This program shows the basics of output and calculations which you will need to do for this program. ---+++ The JES Environment The JES Development environment can be download from the main CS 111 Web Page. ---+++ Running JES on SOME machines in the ACCC Labs JES can be found on *SOME OF* the machines in the ACCC Labs. Not all of the ACCC Labs have this software installed. 1 clicking on the <strong>Start </strong>button (lower left corner of the display) 1 clicking on the <strong>Programming </strong>folder 1 clicking on the *JES RXXXX* application (where XXXX is the release number of the software) ---+ ---+++ Python Programming When doing Python Programming, it is very important to follow a basic Python Template. Below is a file called <a href="https://www3.cs.uic.edu/pub/CS111/Lab1f16/template.py.txt" target="_top">template.py</a>. Note that this wiki site does not keep indentation. However, indentation is very important in python. To help with this the spacing text of "<nbsp>" is placed into the below to show indentation. Please note that <nbsp> is not part of the python language and should not be part of your (or any) python program. <blockquote> <table border="1" cellpadding="0" cellspacing="0" id="table1"> <tbody> <tr> <td bgcolor="#ffffff" valign="top"># This is a comment to describe the below program<br />#<br /># This program is being written for CS 111 for Assignment X<br />#<br /># Author: Your name here<br /># Date: Today's Date<br />#<br /><br />def functionName ():<br /> <nbsp> # place code here<br /> <nbsp> # pay attention to indention! VERY IMPORTANT IN PYTHON!!!<br /> <br /> <nbsp> # create and intialize variables first<br /> <br /> <nbsp> # do any needed calculations<br /> <br /> <nbsp> # print results<br /><br /></td> </tr> </tbody> </table> </blockquote> ---+++ Output in Python To output to the screen, we use the print function. Between the parenthesis, we place the information that we wish to display. To display a string of values (i.e. words), we place the words in double quotes. Such as: <pre> print ("Hello. Hope you have a good day.")</pre> You should also note that in python you can omit the parentheses to get the same result. <pre> print "Hello. Hope you have a good day."</pre> To print out a number or the value of a variable, we place that information between the parenthesis. For example: <pre> print (57)</pre> <pre> print (number)</pre> We can print both some text and a value by placing both of these in between the parenthesis and separating them with a + sign, such as: <pre> name = "Bill"</pre> <pre> print ("The name is " + name )</pre> The + sign when used with two strings will concatenate them together (join them one right after the other) so both values get printed out with one print statement. To do this with numeric values, we must rely on the python function of "str( )" which will represent the numeric value as a string value. This is used as follows: <pre> number = 42</pre> <pre> print ("The answer to the ultimate question is " + str ( number ) ) </pre> 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()_ with nothing between the parathesis. <pre> print ("")</pre> Both produce the same result. You will notice that often the same result can be produced via different approaches. We can also print out multiple values by separating the values with a comma in the print statement. This removes the need for the + operator and the str() function. However an 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: <pre> number = 42</pre> <pre> print ("The answer to the ultimate question is" , number ) </pre> ---+++ Lab Assignment 1 *Due: Wednesday 1/25/2017 by 11:59 pm (i.e. midnight)* Write a Python Program that will contain a function called main( ). This function is to do the following: 1 Print out your name 1 Print out your net-id 1 Print out CS 111 1 Print out your lab time 1 Print out the additional information as described below: *As I Was Going to St. Ives* "As I was going to St Ives" is a traditional English language nursery rhyme which is generally thought to be a riddle. The most common modern version is: <blockquote> As I was going to St. Ives,<br /> I met a man with seven wives,<br /> Every wife had seven sacks,<br /> Every sack had seven cats,<br /> Every cat had seven kits,<br /> Kits, cats, sacks, wives,<br /> How many were going to St. Ives? </blockquote> <img alt="st_ives.jpg" src="http://www.cs.uic.edu/pub/CS111/Lab1f14/st_ives.jpg" /> The answer to the riddle is commonly thought to be 1, the narrator of the rhyme. The man, wives, cats and kits are thought to be going the other way (i.e. coming from St. Ives). You can check out the <a href="http://en.wikipedia.org/wiki/As_I_was_going_to_St_Ives" target="_top"> Wikipedia page on this</a> for more information than you would ever need to know. For the final output of the lab, print out the information about who the narrator "met" while going to St. Ives. That is, print out: * The number of wives * The number of sacks * The number of cats * The number of kits (note: "kits" is short for "kittens") * and, the total number of *living things* met <br />i.e. totaling the man, the wives, the cats and the kits (the sacks are *not* living things) <p> </p> *You are required to use variables, multiplication and addition operations to calculate and determine the answers*. For example: <blockquote> <pre>#declaring variables </pre> <pre>numMan = 1 # determining the number of men </pre> <pre>numWives = numMan * 7 # determining the number of wives </pre> </blockquote> <p> </p> Just storing the value of 7 into the variable numWives is *NOT* enough for full credit for the assignment. <p> </p> You are also required display the values in the variables when showing the information about who the narrator met. When doing this you must also display some text describing any values prior to displaying the values. For example: <blockquote> <pre>print "The number of wives are:" , numWives</pre> </blockquote> *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.py*
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2017-01-23 - 02:14:17 - Main.troy
CS111
Web Page Spr 18
Syllabus Spr 18
Lecture Notes Spr 18
Sample Code Spr 18
Assignments Spr 18
[edit this menu
]
Log In
CS 111 Main Page
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
ABOUT US
Our Department
Recent News
Contact Us
ACADEMICS
Prospective Students
Undergraduate
CS Minor
Graduate
Courses
RESEARCH
Overview
By Faculty
Labs
PEOPLE
Faculty
Adjuncts
Staff
Students
Alumni
Copyright 2016 The Board of Trustees
of the University of Illinois.
webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF