Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def print_text(s, n):
- # Shows how many times the stringlength fits in the integer, adding 1 to length because of the space
- divide = n / (len(s)+1)
- # Initiates the counter
- counter = 1
- # Initiates the stringbuilder
- build_string = ""
- # While the counter is lower than the divider, add the text to the stringbuilder, plus an added space char
- # When loop is done, increases the counter by 1
- while counter <= divide:
- build_string = build_string + s + " "
- counter = counter + 1
- # Checks how many dots will have to be printed to make the string exactly n characters long
- difference = (n - len(build_string)) + 1
- # Sets the counter back to one to loop over the dots
- counter = 1
- # Removes the last space character as per instruction
- build_string = build_string.strip()
- # While the counter is lower than the difference, add a dot to the string
- # When dot has been added, increase the counter by 1
- while counter <= difference:
- build_string = build_string + "."
- counter = counter + 1
- # Prints the final string
- print(build_string)
- # Asks the user for an input string
- s = input("Input a string: ")
- # Asks the user for an input integer equal or lower than 70
- n = input("Input an integer <=70: ")
- # Tries to convert input to integer, if it's not able to, that means input is not an integer
- # Program will ask for an integer again
- try:
- n = int(n)
- except:
- print("\nThat's not an integer")
- print("\nPlease enter integer between 0 and 70\n")
- n = int(input("Input an integer: "))
- # Checks if the given n is between 0 and 70
- # If not, asks user to give a correct input
- # If input is correct, build the numericalstring
- # Then prints numerical string
- # Lastly it calls the print_text function
- if n > 70 or n < 0:
- print("\nPlease enter integer between 0 and 70\n")
- n = int(input("Input an integer: "))
- else:
- numerical_string = '1234567890'*7
- print(numerical_string)
- print_text(s, n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement