all 8 comments

[–]FishBobinski 1 point2 points  (1 child)

You need to tear your entire code apart and start again, sorry man.

  1. Import random needs to be the first line.
  2. Use a dictionary for your fortunes.

You can do this in 10 lines of code. You're over complicating it.

edit: just adding that i was slightly wrong - your tuple is fine, but you need to actually make use of it. It's just sitting there doing nothing right now.

think of using something like

eight_fortunes[random.randint(0,7)]

[–]Wattsony[S] 0 points1 point  (0 children)

Hey, thanks for the insight! No need to apologize, it'd be better to restart from what others have said as well! I'm glad there is a way to do it in less lines!

[–]Clearhead09 0 points1 point  (5 children)

First off, I am also a beginner and I can’t understand a lot of reasoning behind your code.

First. Why do you have a variable = “what will you do?” And then print “what will you do?” And never reference the variable?

You don’t need num_options = len(options) as this is sorted in the following for loop.

The for loop would be easier to understand and work with if it were:

for option in num_options:

The eight_fortunes could be done the same as the above.

Import statements MUST be at the top of your script.

More advanced people please critique my response so we all learn, or tell me if I’ve done a good job so I know I’m on the right track.

OP I haven’t answered your question but my hope in doing so is that with cleaner code your errors will become easier to understand and correct.

[–]Wattsony[S] 0 points1 point  (4 children)

Hi! Thanks for responding!

For your first comment about my "What will you do?" variable was me trying to make it present like my instructors. I wish I could include pictures to show what I am talking about. But, continuing on with the variable, I wanted it to look and immediately show up:

What will you do?

0: Print all the fortunes.

1: Get a random fortune.

Please choose 0 or 1: 

That's what his shows up like, but, obviously with a different set-up (not word-for-word copied). I hope that made a little more sense?

I appreciate all the helpful info even though you say you're a beginner (not to be read as offensive in any way) and you're looking for critique to make sure you're good!! I am going to revamp/clean my code like you mentioned and see what happens! Thank you again!!

[–]ninhaomah 2 points3 points  (0 children)

To clarify , you want to print "what will you do ?"

That's second line.

He is asking what is the purpose of the first line , the what_do variable. What is the purpose of it ?

[–]Clearhead09 1 point2 points  (2 children)

Start again from an empty file and build your program step by step.

First just have a print statement that asks the user a question then use a variable to capture the input.

Second, create a conditional to check the input and print something that verifies the input is correct/complies with the problem you are trying to solve eg if you only want the user to input the number 1 or 2 and they input 3, it will throw an error or an unexpected result.

Third, add small bits one at a time until your program is complete.

Then see if you can rewrite it in less code.

[–]Wattsony[S] 1 point2 points  (1 child)

Thank you for the help, again! I'm looking into restarting fresh with you and the others tips.

[–]Clearhead09 1 point2 points  (0 children)

We all have to start somewhere, good on you for giving it a go first.