Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 145
Image: ubuntu2004
Kernel: Python 3 (system-wide)
<img src="dcu_logo.jpg" style="width:200px;height:200px" />
File "<ipython-input-1-eebd4c14571b>", line 1 <img src="dcu_logo.jpg" style="width:200px;height:200px" /> ^ SyntaxError: invalid syntax
<blockquote> DUBLIN CITY UNIVERSITY<br> NATIONAL INSTITUTE FOR DIGITAL LEARNING<br> OPEN EDUCATION / DCU CONNECTED </blockquote> --- MODULE: C1: IT AND WEB TECHNOLOGY FUNDAMENTALS PROGRAMME(S): <ul> <li>BSC IN INFORMATION TECHNOLOGY </li> <li>BSC IN MANAGEMENT OF INFO TECH/INFO SYST </li> <li>HDIP IN SOFTWARE DEVELOPMENT</li> </ul> <blockquote> <b>ASSIGNMENT 3 2020-2021</b> Commentary are to be included in separate markdown cell(s).Also present the code with appropriate code alignment and indentation. Code may also include comments.

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

#Add your answer to Question 1 here. If you want to use additional cells go ahead. try: result = '' x = int(input('Enter a number: ')) operand = input('Choose an operator, * or + : ') y = int(input('Enter a second number: ')) if operand == '/': print('Cannot accept that operator') elif operand == '-': print('Cannot accept that operator') elif operand == '*': result = x * y elif operand == '+': result = x + y except: print('An error has occured') else: print(result) finally: print('End of Program')

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
#Add your answer to Question 2 here. If you want to use additional cells go ahead. week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] WeekDay = list((week[0:5])) WeekEnd = list((week[5:7])) print(WeekDay) print(WeekEnd)

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

#Add your answer to Question 3-Part 1 here. If you want to use additional cells go ahead. import random as r suits = ['spades', 'clubs', 'hearts', 'diamonds'] faces = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'] deck = [(y,x) for x in suits for y in faces] fullDeck = len(deck) print(*deck, sep='\n') print(type(deck)) print('\n\n') def removecards(): value1 = int(fullDeck) value2 = int(cards) balance = value1 - value2 print(balance) def dealhand(): r.shuffle(deck) global hand_1 global hand_2 hand_1 = deck[0:5] hand_2 = deck[6:11] print(hand_1) print(hand_2) dealhand() print('\n') deltCards = hand_1 + hand_2 cards = len(deltCards) removecards()

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

#Add your answer to Question 3- Part 2 here. If you want to use additional cells go ahead.

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