Lab 2

pdf

School

New York University *

*We aren’t endorsed by this school

Course

1114

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

3

Uploaded by ChancellorDolphinMaster963

Report
CS UY-1113 LAB 2 February 3rd, 2023 Note: Do not use any language construct not taught in the course up to this point. These problems can and all should be solved using the basic data types, user input and output, expressions, the ord and chr functions, and assignment statements. Each Python file created for the problems should contain the following header: # <Your Name> # CS - UY 1113 # 3 February 2023 # Lab 2 # Question No. Problem 1 Given that: A = 8 B = "15" C = 93 D = "yellow" Determine the output of the following expressions (without running it on your computer). It is possible that the code can produce an error. (Note: You might want to refer to the ASCII Table ( http://www.asciitable.com/ ) for some problems.) a) print(A + 5) b) print(B + 20) c) print("An " + D) d) print(chr(C)) e) print(int(B)) (Note: You should submit a python file named lab2_p1.py , and your answers should be written as print statements inside the file.) 1
Problem 2 Open a new file on Thonny and name it lab2_p2.py . In this file, write a program that prints the initials of NYU made entirely of the \, /, |, _, $ and space characters. A sample output is shown below. /$$ /$$ /$$ /$$ /$$ /$$ | $$$ | $$| $$ /$$/| $$ | $$ | $$$$| $$ \ $$ /$$/ | $$ | $$ | $$ $$ $$ \ $$$$/ | $$ | $$ | $$ $$$$ \ $$/ | $$ | $$ | $$\ $$$ | $$ | $$ | $$ | $$ \ $$ | $$ | $$$$$$/ |__/ \__/ |__/ \______/ Problem 3 Open a new file and name it lab2_p3.py . Write a program that asks the user for a Unicode value and prints out the character associated with it. For example, a sample execution could look like the following. Curious about Unicode? Take a look at why we care: https://docs.python.org/3/howto/unicode.html Please enter the Unicode value: 65 The value you entered, 65, represents the character: A Problem 4 Writing a computer program requires describing a particular procedure with no ambiguity at all, so that a machine can interpret your instructions and perform them. To emphasize the importance of clarity in describing a procedure, we’d like you to practice writing an unambiguous procedure in English. Write a procedure using English sentences to sort a list of students alphabetically. You need to be sufficiently clear so that another person could follow the procedure, without any previous understanding of the goal. If the other person is able to reproduce your procedure based only on your written instructions, with no verbal hints, then we can say that your instructions were sufficiently clear. Note that the person executing the sorting procedure has no knowledge of what ”alphabetizing” is. Your procedure should work regardless of the actual content of the list: that is, the procedure 2
should be sufficient for alphabetizing any list of names, not just the list of names given in this assignment. For example, if the list contains the following students: Joetta Melissia Lonnie Antoinette Kathern Lawrence The ordering of this list after your procedure executes should be: Antoinette Joetta Kathern Lawrence Lonnie Melissia Note that you should write a generalized procedure that will work with any list of students. For example, if the same procedure is given the following list of students as input: Birgit Addie Allena Cruz Elvira The ordering of this list after your procedure executes should be: Addie Allena Birgit Cruz Elvira When you have finished writing the procedure, try giving it to another student to follow. The other student should follow the instructions, during which time you should not help them. When the other student has finished, determine if the procedure was successful. (Note: Similar to Problem 1, you should submit a python file named lab2_p4.py , but your answers should be written as a print statement (or multiple print statements if you want, that’s up to you) inside the file.) 3
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