Dec-20-2017, 05:40 PM
Hello everyone, i'm a newbie @ python. about 3-4 months in..-- also new to the forum.
I've been having some problems with some code. The instructions requested for me to invert a triangle.
I was able execute this code.. but it breaks when an empty strings is inputted.
Here is my code: ( When you call the function with with a numeric-string and an integer, the code runs without any issues).
def inverted_tri(t):
another_astk = 0
space = 30
if type(t) == str:
t = int(t) # if end-users enters a string, this converts it to an integer
for x in reversed(range(t)):
if x % 2 == 1:
print(' ' * space,'#' * x)
space = space + 1
inverted_tri(' ') # Calling this function with an empty string breaks it.
here is error message:
ValueError: invalid literal for int() with base 10: ' '
Now I'm trying to figure out a way to prevent an end-user from entering an empty string..( preventing them from breaking the program)...but i'm lost..
I would greatly appreciate some help.. Please do not type out any code containing your examples as to how you would do it; as it would not help me progress
... I would much rather you point me in the right direction ( i.e maybe an article on a particular function and or statement that would help me clear the issue).
I've been having some problems with some code. The instructions requested for me to invert a triangle.
I was able execute this code.. but it breaks when an empty strings is inputted.
Here is my code: ( When you call the function with with a numeric-string and an integer, the code runs without any issues).
def inverted_tri(t):
another_astk = 0
space = 30
if type(t) == str:
t = int(t) # if end-users enters a string, this converts it to an integer
for x in reversed(range(t)):
if x % 2 == 1:
print(' ' * space,'#' * x)
space = space + 1
inverted_tri(' ') # Calling this function with an empty string breaks it.
here is error message:
ValueError: invalid literal for int() with base 10: ' '
Now I'm trying to figure out a way to prevent an end-user from entering an empty string..( preventing them from breaking the program)...but i'm lost..
I would greatly appreciate some help.. Please do not type out any code containing your examples as to how you would do it; as it would not help me progress
