Advertisement
Arthurious

Untitled

Nov 21st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | None | 0 0
  1. def print_text(s, n):
  2.     # Shows how many times the stringlength fits in the integer, adding 1 to length because of the space
  3.     divide = n / (len(s)+1)
  4.  
  5.     # Initiates the counter
  6.     counter = 1
  7.  
  8.     # Initiates the stringbuilder
  9.     build_string = ""
  10.  
  11.     # While the counter is lower than the divider, add the text to the stringbuilder, plus an added space char
  12.     # When loop is done, increases the counter by 1
  13.     while counter <= divide:
  14.         build_string = build_string + s + " "
  15.         counter = counter + 1
  16.  
  17.     # Checks how many dots will have to be printed to make the string exactly n characters long
  18.     difference = (n - len(build_string)) + 1
  19.  
  20.     # Sets the counter back to one to loop over the dots
  21.     counter = 1
  22.  
  23.     # Removes the last space character as per instruction
  24.     build_string = build_string.strip()
  25.  
  26.     # While the counter is lower than the difference, add a dot to the string
  27.     # When dot has been added, increase the counter by 1
  28.     while counter <= difference:
  29.         build_string = build_string + "."
  30.         counter = counter + 1
  31.  
  32.     # Prints the final string
  33.     print(build_string)
  34.  
  35.  
  36. # Asks the user for an input string
  37. s = input("Input a string: ")
  38.  
  39. # Asks the user for an input integer equal or lower than 70
  40. n = input("Input an integer <=70: ")
  41.  
  42. # Tries to convert input to integer, if it's not able to, that means input is not an integer
  43. # Program will ask for an integer again
  44. try:
  45.     n = int(n)
  46. except:
  47.     print("\nThat's not an integer")
  48.     print("\nPlease enter integer between 0 and 70\n")
  49.     n = int(input("Input an integer: "))
  50.  
  51. # Checks if the given n is between 0 and 70
  52. # If not, asks user to give a correct input
  53. # If input is correct, build the numericalstring
  54. # Then prints numerical string
  55. # Lastly it calls the print_text function
  56. if n > 70 or n < 0:
  57.     print("\nPlease enter integer between 0 and 70\n")
  58.     n = int(input("Input an integer: "))
  59. else:
  60.     numerical_string = '1234567890'*7
  61.     print(numerical_string)
  62.     print_text(s, n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement