CMPSC 101 Homework 3

$30.00

Category: Tags: , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (5 votes)

Q1. 30 points
Given two lists of numbers output the numbers which are in both lists.
Note: You may assume no numbers are repeated within a single list
Sample output:
Please enter a list of numbers:
1 5 2 3
Please enter a second list of numbers:
5 6 1
The numbers in both lists are: 1 5
Q2. 30 points
Given two lists of numbers output the numbers which are in one list or the other.
Sample output:
Please enter a list of numbers:
1 5 2 3 1 3
Please enter a second list of numbers:
5 6 1
The numbers in one list or the other are: 1 5 2 3 6
Q3. 40 points
Take a string from the user and output if it a valid variable name. A variable name is valid if it contains
only alphabets, numbers and the underscore character. Additionally it can not start with a number
Sample output I:
Please enter a variable name: abc_123
abc123 is valid
Sample output II:
Please enter a variable name: 1ab
1ab is not valid
Sample output III:
Please enter a variable name: abc___d
abc___d is valid
Sample output IV:
Please enter a variable name: abc%$d
Abc%$d is not valid
Q4. Extra credit 30 points
You are given n and a list of numbers which contain the numbers 1 through n with one of them
repeated. Output which number is repeated without using .count()
Note: for this question checking if a number j is in a list lst twice by using the lst.count(j) == 2 is not
allowed. You have to write your own code to perform this check if you intend to use it
An additional 20 points if you can do this using a single loop
Sample output I:
Please enter n: 5
Please enter the list: 1 2 5 4 3 3
The repeated number is 3
Sample output II:
Please enter n: 4
Please enter the list: 2 3 4 1 2
The repeated number is 2
Sample output III:
Please enter n: 7
Please enter the list: 5 4 7 3 1 2 6 3
The repeated number is 3