Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # CSC 242-503
- # Assignment 1 template
- # Travis Zillmer
- # No collaborator
- from random import choice
- # Question 1
- def makeNumber(s):
- 'extracts integers from a string, returns 0 if no integers inside string'
- res = ''
- for i in s:
- if i in '123456789':
- res += i
- try:
- return int(res)
- except:
- return 0
- pass
- # Question 2
- # This function is provided for your use
- # DO NOT modify it
- def rps(p1, p2):
- 'play a round of rock, paper, scissors'
- p1 = p1.upper()
- p2 = p2.upper()
- if p1 == p2:
- return 0
- elif (p1 == 'R' and p2 == 'S') or (p1 == 'S' and p2 == 'P') or (p1 == 'P' and p2 == 'R'):
- return -1
- else:
- return 1
- # Write this function for the question
- # DID NOT COMPLETE FUNCTION
- def playRPS(n):
- 'Plays a game of rock, paper, scissors between user and the computer using the function rps'
- res = 0
- print('Welcome to the Rock, Paper, Scissors game. \nYou will play {} rounds against the computer.'.format(n))
- while res < n:
- try:
- move = input('Please enter r, p or s for rock, paper, scissors: ')
- res += 1
- except:
- print('That was not a valid choice. Please try again.')
- if results == 0:
- print('That was a tie')
- # Question 3
- import string
- def censor(fname, length):
- "replaces words of size length with a string of x's with the size length"
- infile = open(fname)
- content = infile.read()
- infile.close()
- punctuation = ',.!?'
- table = str.maketrans(punctuation, len(punctuation)*' ')
- words = content.translate(table).split()
- for w in words:
- if len(w) == length:
- w = 'x'*length
- print(w)
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement