What is the result of each of the following computations:
1/2**2*2
int(1.99)
What possible values (in decimal notation) can a 3-bit integer represent? What if it was unsigned?
What is wrong with the following code and how do you fix it?
x = input("what is the square root of 9?")
print(x == 3) # gives false even for right answer
(exercise from slides 03) Rewrite your pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours.
(exercise from slides 03) Rewrite your pay program using try and except so that your program handles non-numeric input gracefully.
Make a function that will takes a string as input and prints a message stating whether string contains an integer, a float, or neither. Demonstrate it works for the following example inputs.
Example usage:
myfunction("3") # outputs 'integer'
myfunction("3.14") # outputs 'float'
myfunction("3.0") # outputs 'float' (or int optionally)
myfunction("hi") # outputs 'just a string'
Make a function with the following requirements (using only the python functionality we have covered thus far in class):
Create functions that do each of the following using only conditional expressions and basic python:
Compute $\frac{A+B}{A*B}$ for two inputs $A$ and $B$
Print the min, max, and median of 3 inputs (FYI: there is no built-in median function)
Accept an input and print whether it is a valid int
Make sure your functions handle bad input cases
Create a function that will print the min, max, and median of 3 inputs using only base python logic, no built-in functions or packages, and show it works with an example.
Create a function that takes three inputs and returns True if exactly two of them are positive numbers (but not three) and show it works.
Create a function that implements the following function and show it works by computing on several values: $$ f(x) = \begin{cases} x + 1 & x < -1 \\ 0 & -1 \le x < 1 \\ x - 1 & x \ge 1 \end{cases} $$
Put your functions in an external .py file and demonstrate you can import it.
Make a function that does the following:
Use only base python for these. As always, do your best to interpret and fulfill the requirements as written.
Given a list of filenames in the following format:
fnames[0] = 'JohnSmith2015-Texas.txt'
fnames[1] = 'MaryJane2016-Mississippi.txt'
Make a python script which extracts three lists from the list of filenames: a list of names, a list of years, and a list of states, all in the same order as in the filenames. So, for example:
names[0] = 'JohnSmith'
years[0] = '2015'
states[0] = 'Texas'
Hint: use mystring.split() and slicing