Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. Problem #2:
  2.  
  3. Write a function called fileStringSearch() that accepts two arguments, one representing a file to open, and the second to accept a string. The function should return True if the string is present in the file. Otherwise it should return False. The second argument must be at least 3 characters in length. If it is not, the function should return -1. This function should NOT be case sensitive. For example, if the string to search for is 'hello', the function should return True even if the file only has 'HELLO' or 'Hello', etc.
  4.  
  5.  
  6.  
  7. Problem #3:
  8.  
  9.  
  10.  
  11. Write a function called problem3() that accepts the year, month, and day. The fourth argument should be a character representing 'A' for 'America', or 'N' for 'Not America'. The function should return a string in which the date has been formatted as follows:
  12.  
  13.  
  14.  
  15. If the fourth argument is 'A':
  16.  
  17. The year is: XXXX. The day is: MM/DD.
  18.  
  19.  
  20.  
  21. If the fourth argument is 'N':
  22.  
  23. The year is: XXXX. The day is: DD/MM.
  24.  
  25.  
  26.  
  27. (Note that there are a couple of colons and periods in this string. They must appear in the returned string).
  28.  
  29.  
  30.  
  31. Example:
  32.  
  33. problemXX(2019, 1, 28, 'A')
  34.  
  35. Should return the string:
  36.  
  37. The year is: 2019. The day is: 1/28.
  38.  
  39.  
  40.  
  41. problemXX(2019, 1, 28, 'N')
  42.  
  43. Should return the string:
  44.  
  45. The year is: 2019. The day is: 28/1.
  46.  
  47.  
  48.  
  49. Bonus 2 points: Set your function up so that if the user does not type any value for the fourth argument, it defaults to the local (i.e. American) version.
  50.  
  51.  
  52.  
  53. Problem #4:
  54.  
  55.  
  56.  
  57. Use "CSV File" called exam_grades.csv. You can find this on the 'Files' page. This is a text file containing a series of students grades on an exam. Every grade is separated from the next by a comma. Feel free to open it in a text editor to see what it looks like.
  58.  
  59.  
  60.  
  61. Write a function that reads in all values in the file. Using the string class' split() method, split your long string into a list of strings. Each string represents a grade. Your function should return the average of all the grades.
  62.  
  63.  
  64.  
  65. Hint: Watch your data types!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement