File "<ipython-input-1-eebd4c14571b>", line 1
<img src="dcu_logo.jpg" style="width:200px;height:200px" />
^
SyntaxError: invalid syntax
Question 1 (25 marks)
Create a simple calculator that that takes in two values x and y and an operator (Multiplication "*" or "+") and carries out the relevant calculation and prints the results. For example if the user puts in the values 3, 4 and the multiplication sign (*) - the result will be 12.
The program should use try/except/else/finally exception handling.
Comments explaining your code are to be included in separate markdown cell(s).
Add your answer in the cell below
Question 2 (25 marks)
Create a list containing the days of the week from Monday to Sunday and two empty lists weekday = [ ] and weekend = [ ]. Allocate each element from the list containing the days to the appropriate list: either weekday or weekend.
Print the weekdays from the weekday list in the order from Monday to Friday.
Print the weekend days from the weekend list in the order Saturday, Sunday.
Comments explaining your code are to be included in separate markdown cell(s).
Add your answer in the cell below
Question 3 - Playing Cards (50 marks in total)
PART 1 (16 marks)
Create a deck of 52 cards. Each card should be represented by a tuple. e.g. ('J', 'spades'). You can use the following Lists:
suits = ["spades", "clubs", "hearts", "diamonds"]
faces = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]
Print out the deck. It should consist of a list of 52 Tuples, one for each card. You can use the following line of code to print: print(*cards, sep="\n")
Include comments in separate markdown cell(s) explaining your code.
Add your answer for Question 3 - Part 1 in the cell below
Question 3-Playing Cards
PART 2 (34 marks)
Part 2-(a)
Import a python library called Random.
Use the random.shuffle() method to shuffle the cards, then deal two hands of five cards each from the deck. The cards should be in two Lists:
hand_1 […] and
hand_2 […].
Print the two hands.
(You can print using the following print command:
print(*cards, sep="\n")
Part 2-(b)
Create a function that removes the dealt cards from the deck after dealing a hand. Print the number of cards left in the deck after each hand is dealt.
Include comments in separate markdown cell(s) for both parts of this question explaining your code.
Add your answer for Question 3 - Part 2 in the cell below
Deliverables:
Note: All code should be included in this notebook. The notebook will be collected on Monday, 5th April 2021.
Question 1:
The deliverables for Question 1 are:
- The cell(s) containing the code. These should be clearly labeled as 'Question 1' in a markdown cell above the code cell(s) along with comments.
Question 2:
The deliverable for Question 2 are:
- The cell(s) containing the code. These should be clearly labeled as 'Question 2' in a markdown cell above the code cell(s) along with comments.
For Question 3:
The deliverable for Question 3 are:
- The cell(s) containing the code. These should be clearly labeled as 'Question 3 Part 1' and 'Question 3 Part 2' in markdown cells above the relevant code cell(s) along with comments.
All your answers should be included in this notebook. Your notebook will be copied to the tutor's area for assessment on the due date. If you wish to apply for an extension of up to one week, then please send your tutor an email in advance.
BEFORE SUBMITTING AN ASSIGNMENT, PLEASE READ THE ASSIGNMENT REGULATIONS SECTION IN THE COURSE HANDBOOK