0% found this document useful (0 votes)
41 views3 pages

cs115 Lab03 v1

This document outlines 3 questions for a Python programming lab assignment on functions. Q1 involves writing functions to check if a word is an isogram and output the results. Q2 involves writing functions to convert text using a key mapping characters, and count numeric characters. Q3 involves writing functions to generate terms of star number and square pyramidal number sequences and get user input to select and output a sequence.

Uploaded by

Serhan Dağlı
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views3 pages

cs115 Lab03 v1

This document outlines 3 questions for a Python programming lab assignment on functions. Q1 involves writing functions to check if a word is an isogram and output the results. Q2 involves writing functions to convert text using a key mapping characters, and count numeric characters. Q3 involves writing functions to generate terms of star number and square pyramidal number sequences and get user input to select and output a sequence.

Uploaded by

Serhan Dağlı
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS 115 - Introduction to Programming in Python

Lab 03

Lab Objectives: Functions

Notes:
● Upload your solutions as a single .zip file to the Lab03 assignment for your section on
Moodle. You must use the following naming convention: Lab03_Surname_FirstName.zip
where Surname is your family name and FirstName is your first name
● You should not use lists, tuples, dictionaries in your solution.
● For each of the functions below, you should include a docstring comment. The docstring
should have the following format:
"""
Summary of what the function is for
Parameters:
param1 (param1 type): Description of param1
Returns:
type: variable/value
"""

Q1: Write a script, Lab03_Q1.py, that does the following:


a. A word in which no letter of the alphabet occurs more than once is called an isogram.
Write a function repeated_letter that takes a word and returns the first repeating
letter.
b. Write a program that inputs a word, and using the above function, displays an
appropriate message explaining why the word entered is an isogram or not.

Sample Run 1: (User inputs are in red)


Enter a word: flowcharting
This word is an isogram. Each letter occurs once.

Sample Run 2: (User inputs are in red)


Enter a word: questionable
Since the letter 'e' occurs repeatedly, it is not an isogram.

Sample Run 3: (User inputs are in red)


Enter a word: programming
Since the letter 'r' occurs repeatedly, it is not an isogram.
Q2: Write a script, Lab03_Q2.py, that converts a given string using the key given below.

Copy the line below in your program and use it as a global variable.

KEY = "a@bpdqi!l1mwnuo0s5t+z2A4B8E3G6WM"

a. Write a function, convert_char, which takes a character as a parameter and returns


the converted version using the key. The black characters are converted to the following
red characters. For instance, if the character 'a' is passed as a parameter, the function
returns the '@' character, for 'b', it will return 'p'. Note: the character 'p' WILL NOT be
converted to the character 'd'. If the character is not found in the KEY it should be
returned without conversion.
b. Write a function, convert_text, which takes a string as a parameter and, using the
convert_char function, converts the given string. For instance, 'Trials' should be
converted to 'Tr!@15' as the return value.
c. Write a function, numerics_count, which takes a string as a parameter and returns
the count of numeric characters in it. E.g. For the text 'Tr!@15', it should return 2.
d. Your program should display appropriate messages as shown in the sample runs below.

Sample Run 1: Enter a phrase for conversion: Funniest Game


(User inputs are Text you entered: 'Funniest Game'
in red) After conversion: 'Fuuu!e5+ 6@we'

Sample Run 2: Enter a phrase for conversion: barbeque party


(User inputs are Text you entered: 'barbeque party'
in red) After conversion: 'p@rpeque p@r+y'
!! Attention !! There is no number in this text

Sample Run 3: Enter a phrase for conversion: published quote


Text you entered: 'published quote'
After conversion: 'pup1!5heq qu0+e'

Sample Run 4: Enter a phrase for conversion: R2D2 & C3PO


Text you entered: 'R2D2 & C3PO'
After conversion: 'R2D2 & C3PO'
No conversion happened.

Sample Run 5: Enter a phrase for conversion:


No phrase entered.
Q3: Write a script, Lab03_Q3.py, that includes the following:

a. A function, star_number,that returns the nth member of the Star Numbers sequence
using the formula below:
𝑓(𝑛) = 6 𝑛(𝑛 − 1) + 1
b. A function, square_pyr_number, which returns the nth member of the Square
Pyramidal Numbers sequence using the formula below:
𝑛(𝑛+1)(2𝑛+1)
𝑓(𝑛) = 6
c. A function show_options which displays the menu shown below:
*** SEQUENCES ***
1. Star Numbers
2. Square Pyramidal Numbers
d. A function, select_sequence,that inputs a selection from the user (either 1 or 2). If
user input is invalid, the function displays a message and keeps prompting for input until
a valid choice is made. The function should return the user’s choice. (Optional: You can
consider returning functions instead of integer values.)
e. Using the functions defined above, write a program to generate the first 10 values of the
selected number sequence. See the sample runs below.

Sample Run 1: (User inputs are in red) Sample Run 3: (User inputs are in red)

*** SEQUENCES *** *** SEQUENCES ***


1. Star Numbers 1. Star Numbers
2. Square Pyramidal Numbers 2. Square Pyramidal Numbers

What is your choice? 1 What is your choice? 3


1 13 37 73 121 181 253 337 433 541 Valid options are 1 or 2.
*** SEQUENCES ***
Sample Run 2: (User inputs are in red) 1. Star Numbers
2. Square Pyramidal Numbers
*** SEQUENCES ***
1. Star Numbers Re-enter your choice: 1
2. Square Pyramidal Numbers 1 13 37 73 121 181 253 337 433
541
What is your choice? 2
1 5 14 30 55 91 140 204 285 385

You might also like