Python Forum
I'm not sure what I'm doing wrong here...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm not sure what I'm doing wrong here...
#3
(Nov-01-2016, 04:29 AM)Larz60+ Wrote: For starters:

Your number1 code
number1 = raw_input("Choose a number.")
def number1():
    if number1 <= 1:
        number1 = "a"
    elif number1 > 1:
        number1 = number1
Very confusing and potential for error exists (even though technically legal) when variables are named the same as functions
also you don't need the elif it does nothing.Why would you have to make a variable equal to itself?
You should also refrain from using globals, but that's something you will pick up with experience ... just keep it in the back of your mind.
In addition, if you're going to the trouble of naming something 'number'... don't store anything but numbers in that variable
finally, you never call this function, so why is it there? and even if you did, you never look for an 'a'

to execute a function, the syntax is functionname(arguments). I think you are confused about this.
defaults should only be used if they make sense, not as a standard way to call a function.
your final_product is a good example of BAD code.

Try fixing things up a bit, then come back with specific issues.
also, next time post the code here (unless it's mile long)


Actually within the body of the function it compares the function object with the number. If you add
print number1
within the function body, it will print the function object, not the value of the global name number1
Also note that raw_input will return str, not int, so without conversion the global name number1 will hold str anyway.
It looks like function object is always greater than int object and the opposite when comparing with str object or when compare str object with int objects

def foo():
    pass
bar=10**100
bar2='some str'
print foo
print bar
print bar2
print foo>bar
print foo>bar2
print bar>bar2
Output:
<function foo at 0x036470B0> 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 some str True False False
Reply


Messages In This Thread
I'm not sure what I'm doing wrong here... - by Fazz - Nov-01-2016, 01:44 AM
RE: I'm not sure what I'm doing wrong here... - by buran - Nov-01-2016, 07:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,977 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  python gives wrong string length and wrong character thienson30 2 3,152 Oct-15-2019, 08:54 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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