print
’s keyword argumentsWhich of the following is printed by: print("B", "C", "D", "BR", sep="A")
What is printed by the following code?
What does the following program print?
Last time I asked you to prompt the user for three numbers and print their sum. The last problem asked you to print the sum without spaces between the numbers and operators. Solve this problem again using what you learned about the print
function’s keyword arguments.
Enter the first number: 4
Enter the second number: 2.4
Enter the third number: 8.6
4.0+2.4+8.6=15.0
For your convience, here is a table of the first 8 powers of two:
2^0: 1
2^1: 2
2^2: 4
2^3: 8
2^4: 16
2^5: 32
2^6: 64
2^7: 128
Write a program that prints the table of powers of two that I provided above. Use one print
call per line and use the sep
keyword argument.
Write a program to extract the s digit from a number , given and . Assume and are both positive integers, and has at least digits. Hint: try using modulus and integer divison together - for example, notice that the 100’s digit of 3624 can be calculated as 3624 // 100 % 10
. A couple example runs are given below:
Enter k: 2
Enter n: 1531
The 100s digit of 1531 is 5
Enter k: 0
Enter n: 13
The 1s digit of 13 is 3
Suppose a variable p
contains a positive integer. Write a Python expression that evaluates to a string containing the binary representation of with no leading zeros. For example: if p = 3, you’d give the binary for , which comes out to 111
. Hint: work out a couple more examples with different values of and see if you can find a pattern.
Typically, integers are stored on computers by default using 64 bits. What’s the largest integer that can be represented using 64 bits? I recommend using a calculator (or Python!) for this one.
Integers can be negative, but computer memory can’t store “+” and “-” signs, only 0s and 1s. For this reason, the decimal-to-binary integer conversion approach I presented doesn’t have any way to represent negative integers. Can you come up with an approach to represent both negative and positive integers using binary?