CSCI1105

View the Project on GitHub

Assignment 3 Question 1 The Old Switcheroo

Instructions

In this problem, you will read in a series of strings and store them to a list. Once you have the list, you will use random integers to generate indexes for switching elements in the list.

PLEASE NOTE

Details

Input

Processing

Output

Sample Input

132123

Alice

was

beginning

to

get

very

tired

STOP!

Sample Output

[‘very’, ‘tired’, ‘beginning’, ‘to’, ‘get’, ‘was’, ‘Alice’]

Sample Input

240125

“This

is

Mr.

Sherlock

Holmes,

and

this

is

Dr.

Watson.”

STOP!

### Sample Output [‘“This’, ‘is’, ‘Mr.’, ‘this’, ‘Dr.’, ‘and’, ‘Holmes,’, ‘Sherlock’, ‘Watson.”’, ‘is’]

### My Solution also hosted here

 
# CSCI 1105
# Assignment 3, Problem 1
# @author: ???

########################################
#  DO NOT CHANGE CODE INSIDE THIS BOX  #
########################################
from random import randint, seed       #
seed(int(input()))                     #
########################################

########### START YOUR CODE AFTER THIS COMMENT ##############

# made an empty list
stringList = []

# made an input variable to add into the empty list but stops 
# adding when it comes across STOP!
stuff = input()
while stuff != "STOP!":
    stringList.append(stuff)
    stuff = input()

# created two random integer to switch place 5 times
for i in range(5):
    randomNumberOne = randint(0, len(stringList)-1)
    randomNumberTwo = randint(0, len(stringList)-1)
    
    # stored one of the value into temp variable to avoid 
    # losing and switched the two values respectively
    temp = stringList[randomNumberTwo]
    stringList[randomNumberTwo] = stringList[randomNumberOne]
    stringList[randomNumberOne] = temp

# printed the list
print(stringList)

Question 2 Random Numbers and Tables

Instructions

You will generate a series of random numbers in groups of three: The first number will be a row number, the second a column number, the third an increment value.

Using the row and column numbers, you will update the appropriate cell in a 5 x 10 (5 row, 10 column) table by the increment value.

For example, if you generate 3, 10, and 2, you will increment the cell whose row index is 3 and column index is 10 by 2.

PLEASE NOTE

In each of the three questions, I have supplied code at the beginning of the starter code to load the randint() function, as well as code to seed the random number generator. You MUST NOT change this code. If you do, your tests may not run properly. Look for the comment statement that tells where you to start your code.

Details

Input

Processing

Output

Sample input/output:

Input

12345

Output

    51    89   103    75   129   148    87   120    92    79 
    
   159    74    98    76    66    80    90    76   110    63 
   
   127   138   129   131   100    84   122    72   100   115 
   
   106    96   122    85    82   105    38   120    62    92
   
   106   115   107   105    96   106    68    80   101    76

Input

54321

Output

   116    92    69    83    78    47    82    90    99    93 
   
    50   138    93   115   143   123    80   120   130    92 
    
   110    59    93    97    65   129   115   113    92   123 
   
   124   153    63    97    99    42    96    88   144    82 
   
   111   115   119   131   108   108   101   111    96    91

My Solution also hosted here

##
# CSCI 1105
# Assignment 3, Problem 2
# @author: ???

########################################
#  DO NOT CHANGE CODE INSIDE THIS BOX  #
########################################
from random import randint, seed       #
seed(int(input()))                     #
########################################

############ START YOUR CODE AFTER THIS COMMENT ################

# made an empty table
table = []

# filled the table with respective amount of rows and columns with zeroes
for i in range(5):
    add = [0] * 10
    table.append(add)

# created a random integer three times to increase the specific 
# cell outputed by two randint by the increment 
for y in range(1000):
    first = randint(0,4)
    second = randint(0,9)
    increment = randint(0,10)
    table[first][second] += increment

# printed the table with each cell having 6 spaces aligned to right
for i in range(5):
    for j in range(10):
        print("%6d" %table[i][j], end="")
    print()

Question 3 Have I Got A Deal For You

Instructions

In this problem, you are the dealer in a game of Gin Rummy, a card game (You can find out more about the game

here

You will not be playing the game, merely dealing the cards. There are four players and each player receives 10 cards. The cards are dealt to the players one by one. That is, Player 1 receives a card, then Player 2, then Player 3, then Player 4. This repeats 9 more times.

A deck of playing cards has four suits: ♠ (spades), ♣ (clubs), ♦ (diamonds), and ♥ (hearts), and each suit contains Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, and a King, for a total of 52 possible cards.

You will use random numbers to choose the suit and number of the cards that are dealt to the players.

You must keep track of what cards have been dealt so that no two players receive the same card. For example, there is only one 10 of ♣; but the random numbers might generate that card as Player 2’s first card and later generate the same card as Player 3’s tenth card. If the card has already been dealt to a player, then the next card is dealt instead.

PLEASE NOTE

Details

Input

Processing

Output

Sample input/output:

Input

23451

Output

Player 1 total: 70

Player 2 total: 63

Player 3 total: 65

Player 4 total: 65

Input

34235

Output

Player 1 total: 70

Player 2 total: 70

Player 3 total: 64

Player 4 total: 47

My Solution also hosted here

 ##
# CSCI 1105
# Assignment 3, Problem 3
# @author: ???

########################################
#  DO NOT CHANGE CODE INSIDE THIS BOX  #
########################################
from random import randint, seed       #
seed(int(input()))                     #
########################################

################# START YOUR CODE AFTER THIS COMMENT ######################

"""
I have set up the code so that sets the card in numerical value

Spade = suit of 1
Club = suit of 2
Diamond = suit of 3
Heart = suit of 4

Then for the card value

Ace = card of 1
2 to 10 = same
Jack = 11 but have actual value of 10
Queen = 12 but have actual value of 10
King = 13 but have actual value of 10

So if 5 of Diamond is drawn, it is noted as 35
if 12 of Heart is drawn, it is noted as 412
if 10 if Spade is drawn, it is noted as 110

"""

# made a list that holds the card they dealt but overall includes 
# every card dealt
onelist = []
twolist = []
threelist = []
fourlist = []
overall = []

# made a list that includes ONLY THE VALUE of the card that they dealt
onevalue = []
twovalue = []
threevalue = []
fourvalue = []

# made a dealing function
def card(result, resultlist, overall):
    suit = randint(1,4)
    card = randint(1,13)
    cardnum = int(str(suit) + str(card))
    
   # if the dealt card is already in the overall(list of already 
   # dealt cards) it keeps going
   while cardnum in overall:
       suit = randint(1,4)
       card = randint(1,13)
       cardnum = int(str(suit) + str(card))
    
   # remembering to change the value for 11, 12 and 13 which is 
   # Jack, Queen and King to 10
   if card == 11 or card == 12 or card == 13:
        card = 10
    
   # added value to their respective list
   result.append(card)
   resultlist.append(cardnum)
   overall.append(cardnum)    


# initiated the loop where each person gets to go 10 times
for i in range(10):
    card(onevalue, onelist, overall)
    card(twovalue, twolist, overall)
    card(threevalue, threelist, overall)
    card(fourvalue, fourlist, overall)

# summed up all the value of the card they dealt    
un = sum(onevalue)
deux = sum(twovalue)
trois = sum(threevalue)
quatre = sum(fourvalue)
    

# printed it
print("Player 1 total:", un)
print("Player 2 total:", deux)
print("Player 3 total:", trois)
print("Player 4 total:", quatre)