Advertisement
Travnar

Untitled

Feb 7th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.76 KB | None | 0 0
  1. # CSC 242-503
  2. # Assignment 1 template
  3. # Travis Zillmer
  4. # No collaborator
  5.  
  6. from random import choice
  7.  
  8. # Question 1
  9. def makeNumber(s):
  10.     'extracts integers from a string, returns 0 if no integers inside string'
  11.     res = ''
  12.     for i in s:
  13.         if i in '123456789':
  14.             res += i
  15.     try:
  16.         return int(res)
  17.     except:
  18.         return 0
  19.     pass
  20.  
  21. # Question 2
  22. # This function is provided for your use
  23. # DO NOT modify it
  24. def rps(p1, p2):
  25.     'play a round of rock, paper, scissors'
  26.     p1 = p1.upper()
  27.     p2 = p2.upper()
  28.     if p1 == p2:
  29.         return 0
  30.     elif (p1 == 'R' and p2 == 'S') or (p1 == 'S' and p2 == 'P') or (p1 == 'P' and p2 == 'R'):
  31.         return -1
  32.     else:
  33.         return 1
  34.    
  35. # Write this function for the question
  36. # DID NOT COMPLETE FUNCTION
  37. def playRPS(n):
  38.     'Plays a game of rock, paper, scissors between user and the computer using the function rps'
  39.     res = 0
  40.     print('Welcome to the Rock, Paper, Scissors game. \nYou will play {} rounds against the computer.'.format(n))
  41.     while res < n:
  42.         try:
  43.             move = input('Please enter r, p or s for rock, paper, scissors: ')
  44.             res += 1
  45.         except:
  46.             print('That was not a valid choice. Please try again.')
  47.         if results == 0:
  48.                   print('That was a tie')
  49.  
  50. # Question 3
  51. import string
  52. def censor(fname, length):
  53.     "replaces words of size length with a string of x's with the size length"
  54.     infile = open(fname)
  55.     content = infile.read()
  56.     infile.close()
  57.     punctuation = ',.!?'
  58.     table = str.maketrans(punctuation, len(punctuation)*' ')
  59.     words = content.translate(table).split()
  60.     for w in words:
  61.         if len(w) == length:
  62.             w = 'x'*length
  63.         print(w)
  64.     pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement