Cpsc111-Fall23-Asg2.

docx

School

Alexander College *

*We aren’t endorsed by this school

Course

111

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

5

Uploaded by JudgeField13026

Report
CPSC111-Introduction to computing By Dr. Ahmed Malki – Asg. #2 (Fall 2023) Assignment 2 Working with functions, repetition, and making decisions Name: _Chiamaka Amanda Alumonah___ Student number: _10134234_ ASSIGNMENT MARK : ________ / 50 Due Date: Monday, Nov. 6 th ( before start of class) As always, all your answers should use functions and every function should have a documentation string explaining the purpose of the function. Use the Python template given below at the top of your program you submit (don’t forget to modify it to include your information; your name and your student number.) # Program: xxxx.py # Author: Enter your Name and student number here # Class: CPSC 111A # Date: Oct. 25, 2023 # Task: Assignment #2 # Purpose: Solving simple functions ___________________ Do not wait until the last minute to do this assignment in case you run into problems. Submit your assignment to the instructor through Canvas INBOX email 1 | am/cpsc111-F23-Asg2.docx Assigned: Wednesday Oct 25, 2023 FYI # ni will hold an integer provided by the user (or takes an integer input from the user) ni = int(input("Enter an integer number: ")) # nf will hold a float number provided by the user (or takes a float input from the user) nf = float(input("Enter a float number: ")) # st will hold a string provided by the user (or takes a string input from the user) st = input("Enter a string: ") # n will hold a number provided by the user (or takes a number input from the user) n = eval(input("Enter a number: "))
CPSC111-Introduction to computing By Dr. Ahmed Malki – Asg. #2 (Fall 2023) Part 1 - Simple Functions [18 points, 6 points each] 1. Write a Python function that will prompt the user to enter two integers and then creates a list "thelist" of random integers in the range of the two entered integers say "start" and "end". Finally, the function should display the elements of the list "thelist" on a single line separated by " ". 2. Write the following function according to its docstring. def evensOnly(thelist): '''(list) -> list of ints Return a list of all the even integers in thelist. Also, modify thelist so that every element that is not an even integer is replaced with the bool False.''' 3. Complete the following function according to its docstring description. Do not use the str method swapcase. def mySwapcase(s): '''(str) -> str Return a copy of the string s with uppercase letters converted to lowercase, and lowercase letters converted to uppercase.''' Part 2 – For loops and while loops questions [12 points, 6 points each] a. Write code equivalent to the code below that uses for loops and does not use while loops. 2 | am/cpsc111-F23-Asg2.docx Assigned: Wednesday Oct 25, 2023
CPSC111-Introduction to computing By Dr. Ahmed Malki – Asg. #2 (Fall 2023) c b. Write code equivalent to the code below that uses while loops and does not use for loops. Part 3 – More functions [20 points] a. Write a function called compare() that  takes  two integers and  returns  the sign of the difference of the two integers (an integer):  -1 if x is less than y, 0 if x is equals to y, or 1 if x is greater than y. For example: compare(-6, 15) will return -1 compare(9, 9) will return 0  compare(99, -87) will return 1 Also, write the code that will demonstrate your function. Be sure to pay attention to proper indentation. 3 | am/cpsc111-F23-Asg2.docx Assigned: Wednesday Oct 25, 2023
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
CPSC111-Introduction to computing By Dr. Ahmed Malki – Asg. #2 (Fall 2023) b. Complete the following function according to its docstring description. c. Write a Python function that asks the user to enter a student's number of credit hours taken at Alexander College. The function should display a message indicating whether the student is a  freshman , a  sophomore , a  junior  or a  senior  according to the following table:   Student’s number of credits Student’s status completed zero or any number less than 30 credit hours Freshman completed a minimum of 30 credit hours Sophomore completed a minimum of 60 credit hours Junior completed a minimum of 90 credit hours Senior  Also, write the code that will demonstrate your function. Be sure to pay attention to proper indentation. Happy computing! N.B : Next, you are going to make sure you can use the submission properly. This will be how you turn in your assignments electronically. The submission procedure only accepts zip files (NOT rar Files) , so you are going to create a “Asg2_YourFirstName_YourStudentID.zip” file containing all the programs you just wrote as well as this document with your name and student number added to it. To create a “.zip” file, find the directory where the files are saved and select all of them. If you right-click on one of the selected files, you should have the option to create an archive by choosing “Send to” then “Compressed “zipped” Folder”. Rename the created “.zip” file and give it the name Asg2_YourFirstName_YourStudentID.zip. 10 marks will be deducted if: 4 | am/cpsc111-F23-Asg2.docx Assigned: Wednesday Oct 25, 2023
CPSC111-Introduction to computing By Dr. Ahmed Malki – Asg. #2 (Fall 2023) 1. the email did not have a full name and a student # in the subject field or 2. the procedure for zipped file is not followed or 3. Python template and documentation are missing or 4. This MS document, with your names and student numbers on it, are not included with the zipped file A score of zero (0) will be given to everyone whose email is empty. 5 | am/cpsc111-F23-Asg2.docx Assigned: Wednesday Oct 25, 2023