Homework 1

Homework 1: Basics of Python Syntax

Due: Thursday 9/22 @ 9:50 AM

Learning Objectives

  • L1: Basics
  • L4: Style

The purpose of this homework is to get you familiar with manipulating variables in Python and writing simple scripts. It will be relatively shorter than later homework assignments, since we haven’t learned very many complex tasks yet.

It is also to get you used to submitting various types of files to Canvas.

Submission Guidelines

You will turn this homework to Canvas under Homework 1.

You should submit your homework as separate files, one for each question.

The first two files should .py files. The last file should be a .pdf file with a short response.

Each should be named as {familyname}_q{number}.{ext}. For exapmle, my submissions would be:

ackles_q1.py
ackles_q2.py
ackles_q3.pdf

(You can format your family name any way you want, just do not include spaces.)

Please remember to follow the Collaboration Policy for all homework assignments.

Homework Questions

Q1: Hello, World

“Hello, world” is a traditional first program in computer science. We are going to continue that tradition in this class.

Write a program that, when run, produces the following output:

Hello, world!

Q2: A Terrible Number Guesser

Write a program that has a variable which is set to any number you want between 1 and 10. The program then asks a user for a number between 1 and 10, and prints both numbers. It then asks the user to compare them and see if they guessed correctly.

For example, if your variable is set to 5, and the user guesses 9, the program should output the following:

Welcome to the random number guesser. 
Please input a number between 1 and 10:  9
You chose 9. The number I chose was 5. Did you guess it?

Q3: Fix it!

Name two things your program could do that would make the terrible number guesser less terrible. That is, what are some things the program could do that would make it more interesting to try to guess the number?

You don’t have to know how to do those two things in Python; just explain in words how you would expand upon the previous program to add functionality.

Assessment

To demonstrate Proficiency, your code needs to produce the outputs specified above. Your written response needs to name at least two things that are algorithmically possible.

To demonstrate Mastery, your code needs to produce the outputs specified above, and also have:

  • Descriptive variable names
  • Useful (but not excessive) comments
  • Good spacing

Your written response needs to name at least two things which are reasonable extensions of the program.