I'm making a script where you guess a movie based off of a quote from it. What I'm wondering is how I make it so that I can take "Terminator" and "The Terminator" and allow spelling mistakes to still be correct.
I tried to look it up but found pretty much nothing.
#Guess that movie, gives a quote and you have to guess it for points, add a high score system.
from random import randint
points = 0
quote1 = randint(0,3)
quote2 = randint(0,3)
quote3 = randint(0,3)
quote4 = randint(0,3)
movieQuoteEasy = ["You're going to need a bigger boat.", "I'll be back.", "Here's Johnny!", "Say hello to my little friend!"]
movieQuoteMedi = ["Luca Brazi Sleeps with the fishes.", "Whatever doesn't kill you simply makes you... stranger.", "You talking to me?", "I love the smell of Napalm in the morning."]
movieQuoteHard = ["Rosebud...", "How am I funny to you? what makes me so funny.", "They call it a Royal with Cheese.", "Go ahead, make my day."]
movieQuoteExtr = ["I tried... at least I did that.", "Gentlemen, you can't fight here this is the way room!", "I'm having an old friend for Dinner.", "The greatest trick the devil pulled was convincing the world he didn't exist."]
movieAnswerEasy = ["Jaws", "The Terminator", "The Shining", "Scarface"]
movieAnswerMedi = ["The Godfather", "The Dark Knight", "Taxi Driver", "Apocalypse Now"]
movieAnswerHard = ["Casablanca", "Goodfellas", "Pulp Fiction", "Dirty Hary"]
movieAnswerExtr = ["One Flew Over the Cuckos Nest", 'Dr. Strangelove', "Silence of the Lambs", "The Usual Suspects"]
print("Welcome to Guess That Movie!")
input()
#Easy Question
print("Easy: " + movieQuoteEasy[quote1])
guess1 = input()
#Takes the value for use input and checks it against the correct answer.
if guess1 == movieAnswerEasy[quote1]:
print("Correct!")
points += 5
print("You have " + str(points) + " points!")
else:
print("Wrong, the correct answer was " + movieAnswerEasy[quote1])
#Medium Question
print("Medium: " + movieQuoteMedi[quote2])
guess2 = input()
#Takes the value for use input and checks it against the correct answer.
if guess2 == movieAnswerMedi[quote2]:
print("Correct!")
points += 5
print("You have " + str(points) + " points!")
else:
print("Wrong, the correct answer was " + movieAnswerMedi[quote1])
#Hard Question
print("Hard: " + movieQuoteHard[quote3])
guess3 = input()
#Takes the value for use input and checks it against the correct answer.
if guess3 == movieAnswerHard[quote3]:
print("Correct!")
points += 5
print("You have " + str(points) + " points!")
else:
print("Wrong, the correct answer was " + movieAnswerHard[quote3])
#Extream Question
print("Insane: " + movieQuoteExtr[quote4])
guess4 = input()
# Takes the value for use input and checks it against the correct answer.
if guess4 == movieAnswerExtr[quote4]:
print("Correct!")
points += 5
print("You have " + str(points) + " points!")
else:
print("Wrong, the correct answer was " + movieAnswerExtr[quote4])
print("\nGreat job, you have " + str(points) + " points.")
input()
exit()
I want to be able to take in 'The Terminator' and just 'terminator'
I know how to solve your problem. The first thing you can do is add .lower() to the end of your input. This will put all of the letters in the user's input in lower case. Like this: guess1 = input().lower. Now it doesn't matter if the user types in upper or lower case. Also; you should do this:
guess1 = input(">>> ").lower() #Allows the user to input lower case letters.
if "terminator" in guess1: #This is probably what you are looking for.
#If the program detects the keyword 'terminator'
#in your guess, then the if statement will execute.
#Whatever happens when the user is correct.
else:
#Whatever happens when the user is incorrect.
I hope I helped you!
Related
I've just started Scala at University and we're currently just doing the basics but I'm moved ahead and want to try making some basic programs to get ahead. I'm currently trying to make a basic dice role guessing program.
I want to add in a feature to replay the game, the counter is to tell the user how many attempts to guess. I know I can add it in somewhere with counter += 1 just not sure where in the program to put it.
Currently compiling does nothing until I input something and I'm unsure why, then when I input something I don't get any results from the if statements it just terminates the program.
import scala.io.StdIn.readInt
import scala.util.Random
object GuessTheNumber {
def main(args: Array[String]): Unit = {
var play = true
var counter = 0 //Allows counting input
var responseGuess = readInt()
val numRange = Random.nextInt(12)
println("Enter your guess of the result of 2, 6 sided dice.")
while(play) {
if (responseGuess == numRange)
println ("You got it right!")
else if (numRange < responseGuess)
("Your guess was too large by" + (responseGuess - numRange) + " the corrrect answer was " + numRange)
else if (numRange > responseGuess)
( "Your guess was too small by" + (numRange - responseGuess) + " the correct answer was " + numRange)
else if (responseGuess < 1)
("Your guess is too small enter 2-12")
else if (responseGuess > 12)
("You entered an invalid number, 2 dice can only equate to a maximum of 12")
}
}
}
A couple things:
You should ask for a guess (the println) before you go get it from the input
All of your else if blocks were missing println statements
You aren't using your counter
Your numRange is incorrect, right now it would return 0 to 11 inclusive
I made those changes, and moved the readInt() inside the while loop to give people multiple chances to guess, once they guess the answer then the loop exited.
var play = true
val numRange = 2 + Random.nextInt(11)
while(play) {
println("Enter your guess of the result of 2, 6 sided dice.")
var responseGuess = readInt()
if (responseGuess == numRange) {
println ("You got it right!")
play = false
}
else if (numRange < responseGuess)
println("Your guess was too large")
else if (numRange > responseGuess)
println( "Your guess was too small")
else if (responseGuess < 2)
println("Your guess is too small enter 2-12")
else if (responseGuess > 12)
println("You entered an invalid number, 2 dice can only equate to a maximum of 12")
}
You can build off of this to get the functionality you need.
You had a few basic errors, but, a really good first attempt. I have included most of the comments in context for clarity. Here is a quick summary of some of the things that needed minor corrections
You forgot to include println in every else clause
You didn't reset the value of play variable causing your program to be stuck in an infinite loop. The while loop kept executing without asking user for any input giving the illusion that nothing was printing
The counter needs to be updated after every attempt within the loop
import scala.io.StdIn.readInt
import scala.io.StdIn.readChar
import scala.util.Random
object GuessTheNumber {
def main(args: Array[String]): Unit = {
var play = true
var counter = 1 //Allows counting input
// Start a loop. As long as the user says he wants to continue, we keep entering the loop
while (play) {
// The game is slightly more clear in my humble opinion if you ask him/her this question after every attempt.
// Otherwise you just have a blinking cursor on screen, without prompting user for input
println("Enter your guess of the result of 2, 6 sided dice.")
// Read his current response
val responseGuess = readInt()
// If you don't have `1 +`, then, 0 could be a potential result
val numRange = 2 + Random.nextInt(11)
if (responseGuess == numRange)
println(s"You got it right! in $counter attempts")
// You were missing println in each of the following cases. Hence the lack of response from your program, since,
// it didn't know you wanted it to print that response
else if (numRange < responseGuess)
println("Your guess was too large by " + (responseGuess - numRange) + " the correct answer was " + numRange)
else if (numRange > responseGuess)
println( "Your guess was too small by " + (numRange - responseGuess) + " the correct answer was " + numRange)
else if (responseGuess < 1)
println("Your guess is too small enter 2-12")
else if (responseGuess > 12)
println("You entered an invalid number, 2 dice can only equate to a maximum of 12")
println("Do you want to continue? (Y/N)")
// Now you are reading a character instead of an integer. Basically a Y or an N
play = readChar() match { // Not sure if you have gotten this far in your course. This syntax is referred to as pattern matching.
// Its basically the same as using if / else
case 'Y' | 'y' => true // If he enters Y or y, we assume he wants to continue.
case _ => // For any other input we abort
println(s"You tried $counter times") // When he does decide to quit, lets tell him how many times he tried
false
}
// After every attempt increment counter within your loop
counter += 1
}
}
}
Hope this helps.
I am trying to find out how to do the Progress equivalent of a "GROUP BY" function. I am trying to write a procedure that will list product inventory information for multiple locations. Right now, it is listing the product information twice; once for each location. I have tried the BREAK BY functional unsuccessfully. My current & desired output and code is below:
Current Output:
Desired Output:
DEF INPUT PARAMETER ip-um AS CHARACTER NO-UNDO.
MESSAGE
"ProdCode" + "^" +
"ProdName" + "^" +
"ProdUM" + "^" +
"GrossPkgdWeight" + "^" +
"QtyOH - LOC1" + "^" +
"QtyOH - LOC2"
SKIP.
FOR EACH product-um WHERE
product-um.gross-pkgd-weight <= 0.0000
NO-LOCK,
EACH product WHERE
product.product-key = product-um.product-key AND
product.can-be-sold = YES
NO-LOCK,
EACH inventory WHERE
inventory.product-key = product.product-key AND
inventory.qoh > 0 AND
inventory.level = 2
NO-LOCK,
EACH um WHERE
um.um-key = product-um.um-key AND
um.um = ip-um
NO-LOCK
BREAK BY product.product-code:
MESSAGE
product.product-code + "^" +
product.product-name + "^" +
um.um-code + "^" +
STRING(product-um.gross-pkgd-weight) + "^" +
IF inventory.level-key-2 = '00000001' THEN STRING(inventory.qoh) ELSE "0"
+ "^" + IF inventory.level-key-2 = '00000002' THEN STRING(inventory.qoh) ELSE "0"
SKIP.
END.
because you accumulate invesntory.qoh in dependency of inventory.level-key-2 the ACCUMULATE stmt is not realy feasible so coding the accumulation manually would be the best choise
DEFINE VARIABLE loc1 AS INTEGER NO-UNDO.
DEFINE VARIABLE loc2 AS INTEGER NO-UNDO.
FOR EACH product-um NO-LOCK
WHERE product-um.gross-pkgd-weight <= 0.0000
,
EACH product NO-LOCK
WHERE product.product-key = product-um.product-key
AND product.can-be-sold = YES
,
EACH inventory NO-LOCK
WHERE inventory.product-key = product.product-key
AND inventory.product-code = product.product-code
AND inventory.qoh > 0
AND inventory.level = 2
,
EACH um NO-LOCK
WHERE um.um-key = product-um.um-key
and um.um = ip-um
BREAK
BY product.product-code:
CASE (inventory.level-key-2):
WHEN "00000001"
THEN loc1 = loc1 + inventory.qoh.
WHEN "00000002"
THEN loc2 = loc2 + inventory.qoh.
END CASE.
IF LAST-OF(product.product-code)
THEN DO:
MESSAGE
product.product-code + "^" +
product.product-name + "^" +
um.um-code + "^" +
STRING(product-um.gross-pkgd-weight) + "^" +
STRING(loc1) + "^" +
STRING(loc2)
SKIP.
ASSIGN
loc1 = 0
loc2 = 0
.
END.
END.
BREAK BY tells the compiler to mark when the FOR EACH has come to the start or end of a break group.To detect these changes you'll need to use one of these functions to detect that change: FIRST(table.field), FIRST-OF(table.field), LAST(table.field), and LAST-OF(table.field).
Once the required function returns true, you can use the ABL supplied functions like ACCUMULATE, COUNT, TOTAL, etc. to display the desired results. Personally I find the concepts a bit hard to get my head around, so I declare some local variables and do the totals that way.
I have a midi file consisting of two parts. Now I need to print out, for each note in part 0 (including rests), which note sounds at the same time in part 1 (and the note that proceeds this).
I can go through all of the notes in part 0 with music21, but how do I find the note at that time in part 1. Will I need to use end times? Or is there a function for this?
for thisNote in s.parts[0].notes:
print thisNote.ps
Here is a very interesting function that let me solve this:
secondPart = s.parts[1]
for thisNote in s.parts[0].notes:
sys.stdout.write('at ' + str(thisNote.offset) + ' toppitch: ' + str(thisNote.ps))
soundingNotes = secondPart.getElementsByOffset(thisNote.offset, mustFinishInSpan=False, mustBeginInSpan=False)
try:
if soundingNotes > 0:
basslength = len(soundingNotes)
except:
basslength = 0
if basslength > 1:
print "oh ow, more then one note sounding in the bass."
if basslength > 0:
if soundingNotes[0].isRest:
sys.stdout.write(' bottompitch: R')
else:
sys.stdout.write(' bottompitch: ' + str(soundingNotes[0].ps)) # + ' from ' + str(soundingNotes[0].offset))
# print the previous note
soundingNotes2 = secondPart.getElementsByOffset(thisNote.offset-1, mustFinishInSpan=False, mustBeginInSpan=False)
Basically, I have several devices I need to pull data from. I get multiple emails when the temperature measures are under or over the set limits. I would like to have a for loop to include all current devices states that are under or over limits into one email.
body = for device_name, 1 do
device_name++ -- I get error here because unexpected symbol near 'for'
"Device Name: " ..device_name.. "\nDevice Location: " ..device_location..
"\n--------------------------------------------------------------" ..
"\nCurrent Temperature: " ..temperature.." F".. "\nTemperature Limit: ("..
t_under_limit.. "-" ..t_over_limit.. " F)" .."\n\nCurrent Humidity Level: " ..
humidity .. "%".. "\nHumidity Limit: (" .. h_under_limit.. "-" ..h_over_limit.. "%)"
.. "\n\n-------Time Recorded at: " ..os.date().. "-------"})
end, -- end for
there is no variable++ syntax in lua. you need to do
variable = variable + 1
also, you can't assign some for loop construct to a variable. so this statement
body = for device_name, 1, ...
isn't valid. maybe you meant...
local body = ""
for device_name = 1, 1
device_name = device_name + 1
body = body.. "my custom message stuff here"
end
As previously noted, there is no ++ operator in Lua. Also, the syntax for the for loop is different from what you wrote.
I would like to add that the big concatenation afterwards would be much more readable using string.format. Here is an enhanced version of your code, in the form a a function taking a table devices parameters in input, each element being a subtable:
local report_model = [[
Device Name: %s
Device Location: %s
--------------------------------------------------------------
Current Temperature: %d °F
Temperature Limit: (%d-%d °F)
Current Humidity Level: %d %%
Humidity Limit: (%d-%d %%)
-------Time Recorded at: %s-------]]
function temp_report(devices)
local report = {}
for i=1,#devices do
local d = devices[i]
report[i] = report_model:format(d.name, d.location,
d.temperature, d.t_under_limit, d.t_over_limit,
d.humidity, d.h_under_limit, d.h_over_limit,
os.date())
end
return table.concat(report)
end
We have project that uses Analysis Services as it's datasource. To try to avoid having to create 100's of queries because of all the selection options we allow, we create our mdx queries with alot of switches and string concatenation. This is our "Data Access Layer". It is a beast to manage and the smallest mistake: missing spaces, mispellings are easy to miss and even easier to accidently include. Does anyone know of a good resource that can help make this more manageable, like a tutorial, white paper or sample project.
To give you an idea of the case logic I'm talking about and it goes on and on...
if (Time == Day)
{
if (Years == One)
{
return (" MEMBER " + CurrentSalesPercent +
" AS ([Sales % " + YearString + " " + StatusType + "]) ");
}
else //2Y
{
return (" MEMBER " + CurrentSalesPercent +
" AS ([Sales % 2Y " + StatusType + "]) ");
}
}
else if (Time == Week)
{
if (Years == One)
{
return (" MEMBER " + CurrentSalesPercent +
" AS ([Sales WTD % " + YearString + " " + StatusType + "]) ");
}
else //2Y
{
return (" MEMBER " + CurrentSalesPercent +
" AS ([Sales WTD % 2Y " + StatusType + "]) ");
}
...
To be honest, I'm not sure if all the different measures and calculations are correct either. But, that's controlled by another team, so we have a little less influence here.
Thanks!
mkt
Have you looked at the way MS generates MDX? If you have SSRS installed, get "Red gate Reflector" and disassemble C:\Program Files\Microsoft SQL Server\MSRS10.MSSQLSERVER\Reporting Services\ReportServer\bin\MDXQueryGenerator.dll
Apart from that, pre-canned queries that take parameters seems pretty standard :(