A document from MCS 260 Fall 2021, instructor Emily Dumas. You can also get the notebook file.

MCS 260 Fall 2021 Homework 3

  • Course instructor: Emily Dumas

Instructions:

  • As with homework 2, for this assignment you will upload your python code directly to gradescope, i.e. you need to create and save .py files on your computer, and then upload those files.
  • This time, the grading will incorporate automated syntax checks. (Last time, the checks were done, but didn't count toward the score.)

Deadline

This homework assignment must be submitted in Gradescope by 10am CST on Tuesday, September 14, 2021.

Topic

This homework assignment is about the topics of worksheet 3, i.e. lists, while loops and for loops.

Collaboration

Collaboration is prohibited, and you may only access resources (books, online, etc.) listed below.

Resources you may consult

The course materials you may refer to for this homework are:

Expected to be most useful:

Allowed and possibly useful, but probably less relevant than the links above:

Point distribution

This homework assignment has 2 problems, numbered 2 and 3. The grading breakdown is:

Points Item
2 Autograder
4 Problem 2
4 Problem 3
10 Total

What to do if you're stuck

Ask your instructor or TA a question by email, in office hours, or on discord.

( 1. There's no problem 1 )

Gradescope will show the results of the automated syntax check of all submitted files as the score for problem 1.

2. Powers

Write a program hwk3prob2.py that asks the user for three integers:

  • A "start value"
  • A "stop value"
  • An exponent, which I'll refer to as k

The program should then print the numbers n**k for each integer n between the start value and stop value (including both endpoints).

Here is an example of what the interface and output should look like. Here the user asks for the cubes of integers from 5 to 10 inclusive.

Start value: 5
Stop value: 10
Exponent: 3
125
216
343
512
729
1000

In this example, the user typed the numbers 5, 10, and 3, and the rest of the text is output from the program.

3. Username picker

Write a program hwk3prob3.py that asks the user to select a username. (The name won't actually be used for anything.)

The rules for usernames are:

  1. The username must not be empty.
  2. There is a list of names that are not allowed (see below).

If the user requests a name that violates either rule, the program should say that name is not allowed and ask again, repeating until they enter an acceptable name. Once they enter an acceptable name, the program should just print "Your username is X" where X is replaced with whatever they entered, and exit.

In [ ]:
# List of prohibited usernames.  Copy this into your code (without this comment).
prohibited_usernames = [ "system", "administrator", "ddumas", "heliotrope", "sudo", "reboot" ]

Here's what it should look like when you run the program:

Select a username: system
That username is not allowed.
Select a username: 
That username is not allowed.
Select a username: sudo
That username is not allowed.
Select a username: grogu
Your username is grogu

Revision history

  • 2021-09-09 Initial publication