Python Forum
Thread Rating:
  • 2 Vote(s) - 1.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Random Shuffle List
#10
Well, you have a lot going on and to be honest, makes very little sense. For instance, in line 45 you have "svar = 0" yet you never use "svar".  Line 49 you have "int()"  but it relates to nothing. Line 51, you have 

if sv == slumpFråga:  # if-sats answer = randomquestion

    print("Correct!")
but "sv" will never be comparable to "slumpFraga" because "sv" is a list and "slumpFraga" is a string, so you will always get "False"

You really need to understand the basics. The link posted by metulbuur is very good and there are many, many tutorials out there for beginners.

Here is a very simply example, see if you can follow along with what is happening.

import random

question = ["Are you happy", "Are you sad"]
choices = ["yes", "no"]
rand_question = random.choice(question)
print("The question is: ", rand_question)
answer = input("What is your answer? ")

if answer in choices:
    print("Your answer is True")
else:
    print("Your answer is False")
Start off small and once it works, slowly build up from there.  Use variable names that make sense. When you print something, make sure you let yourself and others know what it is your printing. And use "print" statements liberally, to make sure variables contain what they ought to contain and your program is progressing as you intend.

Good luck  Smile
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Messages In This Thread
Random Shuffle List - by simon - Oct-20-2016, 11:28 AM
RE: Random Shuffle List - by Yoriz - Oct-20-2016, 11:50 AM
RE: Random Shuffle List - by simon - Oct-20-2016, 12:00 PM
RE: Random Shuffle List - by metulburr - Oct-20-2016, 12:08 PM
RE: Random Shuffle List - by Yoriz - Oct-20-2016, 12:11 PM
RE: Random Shuffle List - by simon - Oct-20-2016, 12:35 PM
RE: Random Shuffle List - by metulburr - Oct-20-2016, 12:38 PM
RE: Random Shuffle List - by simon - Oct-20-2016, 12:39 PM
RE: Random Shuffle List - by simon - Oct-21-2016, 12:53 PM
RE: Random Shuffle List - by sparkz_alot - Oct-21-2016, 02:06 PM
RE: Random Shuffle List - by simon - Oct-24-2016, 04:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Random selection from list Mohsky 1 11,460 Mar-31-2020, 10:27 PM
Last Post: deanhystad
  printing list of random generated rectangles Zatoichi 8 7,439 Feb-18-2018, 06:34 PM
Last Post: buran
  bubble sort random list atux_null 7 8,013 Nov-03-2017, 07:28 PM
Last Post: sparkz_alot
  List with Random Numbers AnjyilLee 5 9,466 Oct-14-2017, 09:22 PM
Last Post: buran
  Using two functions to shuffle a deck of cards bwe587 7 9,286 Feb-15-2017, 08:15 AM
Last Post: wavic

Forum Jump:

User Panel Messages

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