Im trying to make a maths quiz on python but it says a speech mark is a Syntax Error - python-3.2

print ("Congratulations for Completing the School Subject Quiz.")
print (" ")
print ( name " Your score is " + score )
print (" ")
print ("Thank you very much for taking your time and completing my quiz")
print (" ")
print ("Hope you have a great day ")
it says that the second speech mark on Where it tells them there name and there score. Help Would be greatly appreciated.

You are missing the + between name and " Your score is
Without that symbol it looks like you are trying to print a variable named name(space)(quote)(space)Your - when what you are trying to print is the expression name (plus) a literal string

Even better would be f-strings.
print ("Congratulations for Completing the School Subject Quiz.\n")
print (f"{name} Your score is {score}\n" )
print ("Thank you very much for taking your time and completing my quiz\n")
print ("Hope you have a great day ")

Related

print () command and multiple items

Some context, This is some of my first programming in Lua and I am doing it with QSC software.
local a = Controls.Flippy.String
local b = Controls.Flippy.Value
local c = Controls.Flippy.Position
local d = " "
print(a..d..b..d..c)
This worked but is there away I can write strings in line with a variables. Such as:
print("controls "a" "b" "c)
Same way you put the strings together--with .., the concatenation operator.
print("controls "..a.." "..b.." "..c)
It is also possible to use print with multiple arguments, though the spacing is often different (which may or may not be desirable):
print("controls",a,b,c)
You can just write the strings as
print("controls", a, b, c)
You can choose not to put spaces in between if you wish not to.
Hope that helps!
There are several ways to print multiple values in a line.
local name = "Frank"
local age = 15
-- simple, but not applicable for my example due to formatting:
print("My name is", name, "I'm", age, "years old")
-- using the concatenation operator ..
print("My name is " .. name .. ". I'm " .. age .. " years old")
-- using string.format, best for complex expressions, capable of advanced formatting
print(string.format("My name is %s. I'm %d years old.", name, age))

Lua - How to print 2 things in one print statement

In python you are able to print 2 things by using one statement by typing
print("Hello" + " World")
Output would be "Hello world"
So is there a simple to do this again in Lua?
I'm trying to make the statement print the percentage and the percentage sign. This is currently what I have
function update()
local hp = crysHu.Health/ crysHu.MaxHealth
local text = script.Parent.TextLabel
healthBar:TweenSize(UDim2.new(hp,0,1,0),"In","Linear",1)
text.Text = math.floor(hp*100)
end
text.Text = math.floor(hp*100) is the part that I need help with FYI.
doing text.Text = (math.floor(hp*100) + "%") doesn't work.
If you're doing simple string manipulations, you can concatenate them with .. like this :
local foo = 100
print( tostring(foo) .. "%") -- 100%
or if you want more specific formatting you can use string.format
local foo = 100
print( string.format("%d%%", foo)) -- 100%
Use a ,. Its the same for both Lua and Python though Lua puts a tab between them in a print:
print(2, 3) # 2 3
or use io.write but then you need to handle the newline.
io.write("hello", " world\n") # hello world

Netlogo print values and text in the same line

I know how to print a variable and a text but I want to make it in the same line, If i Use:
print "text" MYVARIABLE
I got an exception
Expected command
So the question is: there is a way to print text and variable on the same line?
Thank you
Yes! The word primitive is what you are after- see the dictionary definition here.
In brief, you can follow the syntax:
print word "Count turtles: " count turtles
Or
print ( word "There are " count turtles " turtles right now" )

There are curly braces in my COBOL output

My output in my latest 85 program has displays curly braces after the variables and im wondering why this is.
ex: - TOTALS: BEGN-BAL:00100000{ PAYMNT:0000300{ PURCHS:0002500{ FIN-CHRGE:001659{
actually
{ -> indicates +ve sign and
} -> indicates -ve sign
example: for +10 -->in program take s9(02) --> output: " 1{ "
example: for -10--> in program take s9(02) output-> " 1} "
SIGN - WILL BE STORE IN LAST DIGIT AS A CHARACTERS.

How do I ask for multiple lines of input in Lua

I'm trying to make a basic account creator for a "bank" type thing in my personal time, and I've run into a problem. I created a file called "newAccount" to serve the purpose of making new accounts, but when I run it, it only asks the first question, and then it stops working.
Here's what I have so far.
print("What is the user's name?")
name = read()
file = io.open(name ,"w")
file:write(1, "Name: " + name, "\n")
print("What do they owe?")
owe = read()
file:write(2, "Owe: " + owe, "\n")
print("What is their account balance?")
balance = read()
file:write(3, "Balance: " + balance, "\n")
file:close(name)
After it stops running, it says:
newAccount:4: attempt to perform arithmetic __add on string and string
App has finished, press any key to exit."
Lua uses .. to concatenate strings, not +. Change
"Name: " + name
to
"Name: " .. name

Resources