How do I print 12345, 23451, 34512, 45123, 51234 in python ?
xStr = str(12345)
for x in range(len(xStr)):
[print(xStr[y%len(xStr)], end="") for y in range(x, x + 5)]
print(end=",")
12345,23451,34512,45123,51234,
What is a program that displays the following output using nested loops 12345 2468 369 48 5?
#12345 2468 369 48 5
startNo =1
noOfDigit = 6
for k1 in range(5): ## 5 number to be printed.
for k in range(startNo,10, k1+1): ## change the start and step.
if k == noOfDigit: break ##check the no of digit to print.
print(k, end = "")
noOfDigit = noOfDigit -1 ##every loop decrement.
startNo = startNo + 1 ##every loop increment the start number.
print(end = ",")
12345,2468,369,48,5,
How to check whether s string is integer, float or string ?
x = "99.9"
try:
X = eval(x)
if type(X) == int:
print("This is integer")
else:
print("This is float")
except NameError:
print("This is string")
try:
X = eval(x)
if type(X) == int:
print("This is integer")
else:
print("This is float")
except NameError:
print("This is string")
Write a program to print inverted pyramid of '7'
start = 15 # no of 7 at the first level
count = start*2 + 1
for x in range(start,count):
print(" "*x, str(7)*count)
count = count -2
count = start*2 + 1
for x in range(start,count):
print(" "*x, str(7)*count)
count = count -2
7777777777777777777777777777777 77777777777777777777777777777 777777777777777777777777777 7777777777777777777777777 77777777777777777777777 777777777777777777777 7777777777777777777 77777777777777777 777777777777777 7777777777777 77777777777 777777777 7777777 77777 777 7
0 comments:
Post a Comment