0% found this document useful (0 votes)
37 views

Lab Data

This document provides instructions for a programming lab assignment with 4 questions. Question 1 asks students to write a program that calculates membership prices based on entry type and age. Question 2 asks students to find the maximum odd number from user inputs. Question 3 asks students to draw a triangle of a given size. Question 4 asks students to simulate rolling dice multiple times and calculate the average roll.

Uploaded by

ggvhbnjbhbjh
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)
37 views

Lab Data

This document provides instructions for a programming lab assignment with 4 questions. Question 1 asks students to write a program that calculates membership prices based on entry type and age. Question 2 asks students to find the maximum odd number from user inputs. Question 3 asks students to draw a triangle of a given size. Question 4 asks students to simulate rolling dice multiple times and calculate the average roll.

Uploaded by

ggvhbnjbhbjh
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/ 7

EECS 1015 Introduction to Computer Science And Programming

LAB #3- EECS 1015

(Due: As posted on eClass)


Objectives:

 To learn how to use different control structures (if-statements, for/range(), while)


 To continue learning how to convert mathematical ideas into working code
 To start thinking about general problem solving

_________________________________________________________________________________

Submit two files 1- Notebook (.ipynb), 2- HTML or PDF


https://eclass.yorku.ca/

You may submit files as many times as you like. The most recent submission overwrites all previous
submissions.

____________________________________________________________________________________

Note: For each part you need to create a different cell and use the proper comments (such as Question 1, part
a). Your comments must be clear and indicate the question number, part and the functions or methods you
may use if it’s needed.

1|Page
EECS 1015 Introduction to Computer Science And Programming

Lab questions:

QUESTION 1 (20 marks)

This question is to compute the membership price for a person based on the type of purchase (one time entry or
multiple entry) and their age group (Kid, Youth, and Senior).

1. Your program should first ask the person which type of purchase they want: (1) one time entry or (2)
multiple entry.
2. Your program should then ask the person to select the correct again group: (1) Kid; (2) Youth; or (3)
Senior.
3. You then should compute the fare as follows:

One time entry is $25.50; Multiple entry is $35.00.

If the person is a kid or senior, the fair should be discounted by 40%.

4. After the input, print out the computed fare in the following format:

Total amount due: $25.50 [one time entry (full fee)]

Total amount due: $35.00 [multiple entry (full fee)]

Total amount due: $15.30 [one time entry (reduced fee)]

Total amount due: $21.00 [multiple entry (reduced fee])]

------------------------ Example output 1 ------------------------

(User inputs shown in red)

(1) One time entry or (2) Multiple entry


Enter 1 or 2: 2
Select Age Range:
(1) Kid
(2) Youth
(3) Senior
Enter 1, 2, or 3: 1
Total amount due: $21.00 [multiple entry (reduced fee)]

------------------------ Example output 2 ------------------------

(User inputs shown in red)

(1) One time entry or (2) Multiple entry


Enter 1 or 2: 1
Select Age Range:
(1) Kid

2|Page
EECS 1015 Introduction to Computer Science And Programming

(2) Youth
(3) Senior
Enter 1, 2, or 3: 2
Total amount due: $25.50 [one time entry (full fee)]

------------------------ Example output 3 ------------------------

(User inputs shown in red)

(1) One time entry or (2) Multiple entry


Enter 1 or 2: 1
Select Age Range:
(1) Kid
(2) Youth
(3) Senior
Enter 1, 2, or 3: 3
Total amount due: $15.30 [one time entry (reduced fee)]

QUESTION 2 (20 marks)

The goal is to find the maximum odd number from a sequence of positive numbers entered by the user.

Stop prompting the user for numbers after they enter a negative number.

1.Repeatedly prompt the user to enter positives numbers.

2. Keep track of the largest odd number entered by the user?

Hint: How do you know if a number is odd? Any number modulus two that results in a 1 is an odd
number.

For example: 5 % 2 = 1 (odd), 4 % 2 = 0 (even), 12 %2 = 0 (even), 101%2=1 (odd)

3. When the user enters a negative number, stop and print out the largest odd number entered.

4. If the user does not enter an odd number, output 0 as the output and print “No odd number was
provided”.

------------------------ Example output 1 ------------------------

(User inputs shown in red)

Keep entering positive integer


To quit, input a negative integer
Enter a number : 10

3|Page
EECS 1015 Introduction to Computer Science And Programming

Enter a number : 11
Enter a number : 103
Enter a number : 99
Enter a number : 88
Enter a number : -1
Largest odd number: 103

------------------------ Example output 2 ------------------------

(User inputs shown in red)

Keep entering positive integer


To quit, input a negative integer
Enter a number : 99
Enter a number : 109
Enter a number : 122
Enter a number : 44
Enter a number : 8008
Enter a number : 9387
Enter a number : 33
Enter a number : 99
Enter a number : 806
Enter a number : -1
Largest odd number: 9387

------------------------ Example output 3 ------------------------

(User inputs shown in red)

Keep entering positive integer


To quit, input a negative integer
Enter a number : -1
Largest odd number: 0 <- No odd number was provided.

4|Page
EECS 1015 Introduction to Computer Science And Programming

QUESTION 3 (30 marks)

Draw a triangle based on a number between 5-20 that the user provides.
1. Ask the user to input a number between 5 and 20
If the number they input is not between 5 and 20, ask again until it is.

2. Draw a triangle as shown below.


------------------------ Example output 1 ------------------------
(User inputs shown in red)

Enter size between 5 and 20: 2


Enter size between 5 and 20: 21
Enter size between 5 and 20: 5
\ <- 1 a single '\'
-\ <- 2 1 '-' followed by a '\'
--\ <- 3 2 '-' followed by a '\'
---\ <- 4 .
----\ <- 5 .
-----| <- 6 5 '-' followed by a '|'
----/ <- 7 4 '-' followed by a '/'
---/ <- 8 3 '-' followed by a '/'
--/ <- 9 .
-/ <- 10 1 '-' followed by a '/'
/ <- 11 a single '/'

------------------------ Example output 2 ------------------------


(User inputs shown in red)

Enter size between 5 and 20: 7


\ <- 1 a single '\'
-\ <- 2 1 '-' followed by a '\'
--\ <- 3 2 '-' followed by a '\'
---\ <- 4 .
----\ <- 5 .
-----\ <- 6 .
------\ <- 7 .
-------| <- 8 7 '-' followed by a '|'
------/ <- 9 6 '-' followed by a '/'
-----/ <- 10 5 '-' followed by a '/'
----/ <- 11 .
---/ <- 12 .
--/ <- 13 .
-/ <- 14 1 '-' followed by a '/'
/ <- 15 a single '/'

5|Page
EECS 1015 Introduction to Computer Science And Programming

QUESTION 4 (30marks)

This task is to help you with while-loops, for-loops, and summing values.

Rolling dice is a random process – the values for each dice can be 1 to 6. However, the expected value of the

sum of two dice is 7. This can be observed by rolling two dice many times and computing the average of the

results. As the number of dice rolls approaches "infinity," the average will converge to the "expected value."

Task 3 is to code this up.

Your task should do the following:

1. Ask the user to enter the number of times they would like to roll the two dice (let's call this N).

2. Loop N times – at each loop, select two random numbers between 1-6 to simulate dice rolls.

3. Print out the two dice values, their sum, and the current roll iteration (starting from 1).

4. When the loop completes, print the average value (with precision 2) of all the dice (i.e., add up all the

rolls and divide by N).

5. Ask the user if they'd like to do this again. If they input 'Y' or 'y', go back to step 1.

6|Page
EECS 1015 Introduction to Computer Science And Programming

------------------------ Example output 1 ------------------------


(User inputs shown in red)

------------------------ Example output 2 ------------------------


(User inputs shown in red)

7|Page

You might also like