import sys
def try_input(prompt, format):
value_count = 5
print prompt
fp1 = float(raw_input("fp1: "))
i = int(raw_input("i: "))
j = int(raw_input("j: "))
word1 = raw_input()
size_word1 = sys.getsizeof(word1)
word2 = raw_input()
size_word2 = sys.getsizeof(word2)
print "The input format string for scanf_s() is: \"%s\"" %format
print "Count of bytes read = ", (size_word1 + size_word2)
print "Count of values read = %d" % value_count
print "fp1 = %f i = %d j = %d" %(fp1, i, j)
print "word1 = %s word2 = %s" %(word1, word2)
try_input("Enter as input: -2.35 15 25 ready2go ", "%f %d %d %[abcdefghijklmnopqrstuvwxyz] %*1d %s%n" )
try_input("Enter the same input again: ", "%4f %4d %d %*d %[abcdefghijklmnopqrstuvwxyz] %*1d %[^o]%n")
try_input("Enter as input: -2.3 15 25 ready2go\n","%4f %4d %d %*d %[abcdefghijklmnopqrstuvwxyz] %*1d %[^o]%n")
value_count = 2
print "Enter: fp1 = 3.14159 i = 7 j = 8"
print "Input: "
fp1 = float(raw_input("fp1: "))
i = int(raw_input("i: "))
j = int(raw_input("j: "))
print "Output:"
print "Count of values read = ", value_count
print "fp1 = %f\ti = %d\tj = %d " %(fp1, i, j)
value_count = 3
print "Enter: 3.14 3.14 3.14"
print "Input: "
fp1 = float(raw_input("fp1: "))
fp2 = float(raw_input("fp2: "))
fp3 = float(raw_input("fp3: "))
print "Output: "
print "Number of values read = ", value_count
print "fp1 = %f fp2 = %f fp3 = %f" %(fp1, fp2, fp3)
print "Enter three integer values: "
n = 3
i = int(raw_input())
j = int(raw_input(), 16)
k = int(raw_input(), 8)
print "Output:"
print "%d values read." % n
print "i = %d j = %d k = %d " %(i, j, k )
print "Enter your first initial: ",
initial = raw_input()
print "Enter your first name: ",
name = raw_input()
if(initial != name[0]):
print "%s, you got your initial wrong. " % name
else:
print "Hi, %s. Your initial is correct. Well done! " %name
print "Enter your full name and your age separated by a comma: ",
name_age = raw_input()
print "Your name is %s and you are %s years old." %(name_age.split(',')[0], name_age.split(',')[1])
print "Enter your first initial: ",
initial = raw_input()
print "Enter your first name: ",
name = raw_input()
if(initial != name[0]):
print "%s, you got your initial wrong. " % name
else:
print "Hi, %s. Your initial is correct. Well done! " %name
print "Enter a sequence of integers and alphabetic names in a single line(separated by spaces): ",
text = raw_input()
split_text = text.split(' ')
for element in split_text:
if element.isdigit():
print "Integer Value: ", element
elif element.isalpha():
print "Name: ", element
else:
pass
i = 15
j = 345
k = 4567
li = 56789
lj = 67891234567
lk = 23456789
print "i = %d j = %d k = %d li = %6.3d lj = %6.3d lk = %6.3d" %(i ,j, k, i, j, k)
print "i = %-d j = %+d k = %-d i = %-6.3d j = %-6.3d k = %-6.3d " %(i ,j, k, i, j, k)
print "li = %d lj = %d lk = %d " %(li, lj, lk)
print "li = %d lj = %d lk = %d " %(li, lj, lk)
k = "678"
hex_k = int(k, 16)
oct_k = int(oct(int(k)))
k = 678
print "%%d %%o %%x %%X "
print "%d %d %d %d " %(k, oct_k, hex_k, hex_k)
print "|%%8d \t|%%-8d \t|%%+8d \t|%%08d \t|%%-+8d"
print "|%8d |%-8d |%+8d |%08d |%-+8d |" %(k, k, k, k, k)
fp1 = 345.678
fp2 = 1.234E6
fp3 = 234567898.0
fp4 = 11.22334455e-6
print "%f %+f %-10.4f %6.4f" %(fp1, fp2, fp1, fp2)
print "%e %+E\n" %(fp1, fp2)
print "%f %g %#+f %8.4f %10.4g " %(fp3,fp3, fp3, fp3, fp4)
import string
count = 0
print "The printable characters are the following: "
printable = string.printable
for char in printable:
if count % 32 == 0:
print ""
print char,
count += 1