Python Forum
I need help with ValueError in my code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help with ValueError in my code
#4
Sorry about that:

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(' ')

(Dec-20-2017, 08:44 PM)wavic Wrote: Hello!
First, put your code between Python code tags ( BBcode )! To preserve indentation use CTRL+SHIFT+V key combo to paste the code.

An empty string cannot be converted into an integer. The string is 't', right? You can check for an empty string by if statement easy: if t:. This will return False if 't' == "". Also, you can check if the strings contain digits only by t.isdigit().

Ref: https://docs.python.org/3.5/library/stdt...ng-methods


thanks for that, i'll try a few things out and let you know.
Reply


Messages In This Thread
RE: I need help with ValueError in my code - by flatman123 - Dec-20-2017, 11:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I am getting ValueError from running my code PythonMonkey 0 1,534 Dec-26-2021, 06:14 AM
Last Post: PythonMonkey
  Error in the code ->ValueError: could not convert string to float: ' ' eagleboom 1 3,272 Nov-29-2019, 06:19 AM
Last Post: ThomasL
  Python- Help with try: input() except ValueError: Loop code to start of sequence Aldi 2 6,495 Mar-08-2018, 03:46 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020