Here is my code:
name = input("What's your name? ")
age = input("how old are you? ")
age_in_dog_years = age * 7
print(f"{name}you are {age_in_dog_years}in dog years.")
The error I get is:
File "input.py", line 7
print(f"{name} you are {age_in_dog_years} in dog years.")
^
SyntaxError: invalid syntax
can't seem to understand the rror
Related
While running the test case, my code is failing as the expected value in hex is different then my answer.
for example, my ws_std value is 13.06 i.e. var1
md5(str.encode(var1)).hexdigest() giving hex value as 382fbe213f159eecf85facb256f265d0
But I am not sure if it matches with the hex value.
Getting error in below code :-
variables = ["ws_std", "p_range", "corr", "dew_month", "max_gust_month", "max_gust_value", "avg_temp", "temp_range", "max_p_range_day", "num_days_std", "median_b_days"]
answers = [ws_std, p_range, corr, dew_month, max_gust_month, max_gust_value, avg_temp, temp_range, max_p_range_day, num_days_std, median_b_days]
answer_dict = dict()
for var, ans in zip(variables, answers):
answer_dict[var] = md5(str.encode(ans)).hexdigest()
with open('test_files/hash.pk', 'rb') as file:
hash_dict = pickle.load(file)
def test_ws_std():
assert hash_dict["ws_std"] == answer_dict["ws_std"]
Error Code:-
========================================================== FAILURES ==========================================================
________________________________________________________ test_ws_std _________________________________________________________
def test_ws_std():
> assert hash_dict["ws_std"] == answer_dict["ws_std"]
E AssertionError: assert 'c8cc550afa85...2c6946c238f36' == '382fbe213f159...facb256f265d0'
E - c8cc550afa85496c4ee2c6946c238f36
E + 382fbe213f159eecf85facb256f265d0
test.py:40: AssertionError
see comments below .
output required : ws_std
Code:
def profile(name, age, lang1,lang2,lang3, lang4, lang5):
print("이름 : {0}\t나이 : {1}\t".format(name,age), end="")
print(lang1,lang2,lang3,lang4,lang5)
SyntaxError: invalid syntax
C:/Users/man/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/man/Desktop/python work space/edu.py"
File "", line 1
C:/Users/man/AppData/Local/Programs/Python/Python38-32/python.exe "c:/Users/man/Desktop/python work space/edu.py"
I don't know how to fix it please help me.
I created a variable called "age = 23". I try and add it to another variable called "message" and specify it as a string using the (str) tag in front of the "age" variable.
age = 23
message = "Happy " + (str)age + "rd
birthday!"
print(message)
But whenever I try and run the code it comes back with a snytax error that looks like this:
line 7
message = "Happy " + (str)age + "rd
birthday!"
^
SyntaxError: invalid syntax
1|potter:/ $
You have the brackets in the wrong place, I'm not going to use your example as you've added it as an image, as AChampion mentioned, but an example is:
number = 34
message = "The number is " + str(number)
print(message)
I'd recommend taking some time to read the Python documentation, as this can help get your head around the language and its more basic uses.
message = "Happy " + str(age) + "rd birthday!"
print(message)
If you are learning Python from other languages such as C, you might know this method:
age = 23
print ('Happy %srd birthday!' % (age))
print ('Happy {}rd birthday!'.format(age)) # Use this
Might help: https://pyformat.info/
I'm quite new in Groovy.
Basically I load a text file, then I need to get a specific value at one line (actually the 6th).
The line is like:
STATIC_ASSERT(VERSION == 888888, "blablabla");
I need to get the 888888 value.
I found a way using multiple split but it's ugly.
I also think of using something like:
line.substring(ind+"VERSION ==".length(), line.length()-10).trim();
But the "blablabla" length can change..
Thank you.
Edit: It works using an hardcoded string like this.
But when I try to run it from the file I get this error:
test' is failed: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script1516208488151762512206.groovy: 4: expecting '}', found '' # line 4, column 69.
ne.contains('VERSION ==')
^
1 error
Here is my code:
${groovy:
String Ver
def file = new File("C:\\test.cpp")
def data = file.filterLine { line ->
line.contains('VERSION ==')
}
Ver = data.split("==")[1].split(",")[0].trim()
logger.info(Ver)
}
--
I also tried something like this:
${groovy:
String Ver
def file = new File("C:\\test.cpp")
while ((line = file.readLine())!=null)
{
int ind = line.indexOf("VERSION ==")
if (ind >= 0)
{
Ver = line.split("==")[1].split(",")[0].trim()
}
}
logger.info(Ver)
}
But I get same kind of weird error:
expecting '}', found '' # line 9, column 58.
("==")[1].split(",")[0].trim()
^
1 error
:(
You do as shown below:
def line = 'STATIC_ASSERT(VERSION == 888888, "blablabla");'
println line.split('==')[1].split(',')[0].trim()
Hello my Problem is to get my data out of an sip.voidptr.
Before I used Python 2.7 and this code:
def winEvent(self, message):
WM_COPYDATA = 0x004A
if message.message == WM_COPYDATA:
if sys.version.find("64 bit") != -1:
structure = ctypes.string_at( message.lParam, 24 )
data = struct.unpack("QQP", structure)
unused, str_len, str_adr = data
my_string = ctypes.string_at( str_adr, str_len )
Now I use Python 3 and had changed from "winevent" to "event_Type".
Does anybody have an idea or an example how to get the data out of the sip.voidptr?
The error massage i get is:
File "C:\OSGEO4~1\apps\Python36\lib\ctypes\__init__.py", line 488, in string_at
return _string_at(ptr, size)
OSError: exception: access violation reading 0x0000000000000001
and before I get as my_string:
Name ID
1 1_2
2 1_3
3 1_4
4 1_5