Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
General Tech Technology & Software 2 years ago
Posted on 16 Aug 2022, this text provides information on Technology & Software related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
This is my first program that uses more than just boring ol' if/else statements - I made a whole 246 line game that's still a work in progress simply using if/else - and I'm going to email this to my teacher later tonight.
if
else
Please suggest more things I can add and report any bugs (although I've found none so far).
# Starting points value points = 0 # correct() calls this def correct(): global points points = points + 1 print("Correct!") print("You have",points,"points!") a = input() # incorrect() calls this def incorrect(): print("Incorrect!") ab = input() print("Welcome to this five question general IT quiz!") print("If you're stuck and need help, type 'Hint'!") a = input() # Question 1 print("Question one:") q1 = input("What does LAN stand for?") if q1 == "Hint": print("The N stands for network...") q1 = input("What does LAN stand for?") elif q1 == "hint": print("The N stands for network...") q1 = input("What does LAN stand for?") if q1 == "Local Area Network": correct() elif q1 == "local area network": correct() elif q1 == "Local area network": correct() elif q1 == "Local area Network": correct() else: incorrect() # Question 2 print("Question 2:") print("Fill in the blank.") q2 = input("A monitor is an example of an ------ device.") if q2 == "Hint": print("Another example would be speakers or headphones.") q2 = input("A monitor is an example of an ------ device.") elif q2 == "hint": print("Another example would be speakers or headphones.") q2 = input("A monitor is an example of an ------ device.") if q2 == "Output": correct() elif q2 == "output": correct() else: incorrect() # Question 3 print("Question 3:") q3 = input("True or false: To connect to the internet, you MUST have an ethernet cable connected from your router to your PC.") if q3 == "Hint": print("Remember, there are two types of internet connecttion.") q3 = input("True or false: To connect to the internet, you MUST have an ethernet cable connected from your router to your PC.") elif q3 == "hint": print REPLY 0 views 0 likes 0 shares Facebook Twitter Linked In WhatsApp
First, you can't possibly check for all possible uppercase/lowercase combinations of the answers, and it is looking messy even as it currently is. This is the perfect place to convert the input to lowercase like this:
q1 = input("What does LAN stand for?").lower()
Now, all you need to do is check for "hint" and "local area network" for question one:
if q1 == "hint": print("The N stands for network...") q1 = input("What does LAN stand for?").lower() if q1 == "local area network": correct() else: incorrect()
In question five, you have multiple inputs. Why don't you handle it like this instead of having multiple if/elif/else statements?
elif
if q5 == "hint": print("A better one of these will boost grapical performance and framerate in games.") q5 = input("Radeon, EVGA, XFX and Sapphire are companies that make what computer component?").lower() if s in ['gpu', 'gpus', 'graphics card', 'graphics cards']: correct() else: incorrect()
In this print call, you should put spaces around your string literals and variables to make it easier to read:
print
print("You have",points,"points!")
q1 isn't a very descriptive variable name, and it does not hold the question, as it suggests. Also, why are you using one variable name for each question? This code can be cleaned up a lot by creating a method to administer the questions:
q1
def administer_question(question, answers, hint): while True: user_answer = input(question) if user_answer == "hint": print(hint) elif user_answer in answers: correct() return else: incorrect() return
Now, the user can input "hint" as many times as they wish.
This is called as:
administer_question("Radeon, EVGA, XFX and Sapphire are companies that make what computer component?", ["gpu", "gpus", "graphics card", "graphics cards"], "A better one of these will boost graphical performance and frame rate in games.")
I would pass a string to the incorrect() function to display the correct answer to the user:
incorrect()
def incorrect(correct_answer): print("Incorrect!") print("The correct answer is '", correct_answer, "'") pause = input()
Note also that I renamed the variable ab to pause so it demonstrates better that the program is just waiting for the user to input a value to continue. However, with all these pauses for input, maybe you should explain that to the user so they don't wait for the program to respond and wonder what is going on.
ab
pause
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
General Tech 10 Answers
General Tech 7 Answers
General Tech 3 Answers
General Tech 9 Answers
General Tech 2 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.