![]() |
|
I need some help with a basic script - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Python (https://sinister.ly/Forum-Python) +--- Thread: I need some help with a basic script (/Thread-I-need-some-help-with-a-basic-script) |
I need some help with a basic script - Zedd - 01-05-2015 Hey guys, Learning some Python here and I'm a little bit stuck on a script I need to write. Basically the instructions are as follows: The Big If Really great work! Here's what you've learned in this unit: Comparators Code: 3 < 4
5 >= 5
10 == 10
12 != 13Boolean operators Code: True or False
(3 < 4) and (5 >= 5)
this() and not that()Conditional statements Code: if this_might_be_true():
print "This really is true."
elif that_might_be_true():
print "That is true."
else:
print "None of the above."Let's get to the grand finale. Instructions Write an if statement in the_flying_circus(). It must include:
Don't forget to include a ":" after your if statements! Be careful with your indentation—the_flying_circus() is a function (which we'll get to in the next unit), and as you can see from the comment, function blocks are indented the same way if, elif, and else blocks are. Your code should look something like this: Code: def the_flying_circus():
if condition:
# Do something!
elif condition:
# Do something else!
else:
# Do yet another thing!I just keep getting stuck because I don't think I fully understand the actual idea behind some of these concepts. Specifically booleans. If someone could help me out with this code and then actually explain like I'm five how you did I would really appreciate it! Thanks in advanced haha! RE: I need some help with a basic script - roger_smith - 01-05-2015 Not exactly sure what all you need help with, but I'll do my best. I took a python class a couple years ago. As far as booleans go, they're typically a "yes" or a "no." Think of them as true or false. Usually it's 0 is false, 1 is true. so some pseudo code would be "if statement is true, do action." Are you learning under python2 or python3? My class was python3. If you have any additional questions or need additional help, don't hesitate to ask. There are a lot of people on this board way better than I at programming. RE: I need some help with a basic script - Customer - 01-05-2015 (01-05-2015, 05:31 PM)roger_smith Wrote: Not exactly sure what all you need help with, but I'll do my best. I took a python class a couple years ago. As far as booleans go, they're typically a "yes" or a "no." Think of them as true or false. Usually it's 0 is false, 1 is true. so some pseudo code would be "if statement is true, do action." You really are a great SMOD, and that's coming from an oldfag of SL. You're a good reason MOTM should come back when we pick up on activity. This is off topic, but it needs to be said. RE: I need some help with a basic script - Zedd - 01-05-2015 Hey roger_smith thanks for the help. Basically I'm trying to write a very basic code and I'm getting caught up when I begin compiling it. I'm taking a course on Python through codecademy.com so I only assume that it is Python3. Which, bear with me here, another assumption is the newest version of the language? Anyays the instructions are simple, I have this code already pre-written for me so basically I need to fill in the blanks. Code: # Make sure that the_flying_circus() returns True
def the_flying_circus():
if ________: # Start coding here!
# Don't forget to indent
# the code inside this block!
elif ________:
# Keep going here.
# You'll want to add the else statement, too!Here are the only requiremnts for the code in order to pass Code: Write an if statement in the_flying_circus(). It must include:
[*] if, elif, and else statements;
[*]At least one of and, or, or not;
[*] A comparator (==, !=, <, <=, >, or >=);
[*] Finally, the_flying_circus() must return True when evaluated.This I'm just not really sure where to go. I had a code written but I deleted it so I can't show you what it said. but I was getting this error Code: Oops, try again. the_flying_circus() should return True, instead it returned: <function the_flying_circus at 0x7fd2af3bf8c0>RE: I need some help with a basic script - The Protagonist - 01-05-2015 Your function didnt return any values. What did you put after your if and else statements? Whichever is actually true should have Code: return TrueYou dont need to use the string "True" as the word True is like numbers, it's part of the languages construct. RE: I need some help with a basic script - Zedd - 01-05-2015 I figured it out. Thanks guys haha Code: answer = "Mario"
def the_flying_circus():
if answer=="Mario" and "Luigi":
return True
elif answer=="Sonic":
return False
else:
return FalseRE: I need some help with a basic script - roger_smith - 01-05-2015 (01-05-2015, 06:41 PM)Zedd Wrote: I figured it out. Thanks guys haha Good job sorting it out. |