How do you print a variable with text in python 3.6.4 - python-3.6

My code is:
snipername = str(input("What's the Sniper's name again?"))
print ("That's right,(snipername)! ")
(snipername) is my varible, but i can't figure out how to print it as well as the message.
Any help would be greatly apprectiated!

Use print("That's right, %s!" % (snipername))

Related

(autoit)sending random words from text file but it gives errors

hello im trying to read and write (send) text from words text file but it gives me bunch of errors i'm kinda newbie please be gentle to me thank you so much.
$File = FileReadToArray("words.txt")
$RandomWords = $File[Random(0, UBound($File) - 1, 1)]
send ("$RandomWords")
sleep (1000)
send ("{enter}")
I'm certain there are better ways of doing it but if you're wanting to send one random line from a text file, this should work.
#include <file.au3>
$File = "words.txt"
$Lines = _FileCountLines($File)
$word = FileReadLine($File, Random(0, $Lines))
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send($word)
This will select the random line and send it to notepad.

String Formatting with python3

Ok so basically I have the following code:
name=raw_input("What is your name?")
quest=raw_input("What is your quest?")
print ("As so your name is %s, your quest is %s ") %(name,quest)
This runs perfection in Python 2.7.9
I have tried to run this same exact code in Python 3.4.2 and it does't work (figured), so I modified it to this thinking it would work:
name=input("What is your name?")
quest=input("What is your quest?")
print ("As so your name is %s, your quest is %s ") %(name,quest)
And this:
name=input("What is your name?")
quest=input("What is your quest?")
print ("As so your name is {}, your quest is {} ") .format(name,quest)
And of course that didn't work either, I have searched for over an hour now multiple sites, what am I missing here? How do you do this in Python 3.4.2, all I keep getting is sites and answers showing you the first way (I listed), and all it does is work on the older version python 2.
Thanks
print is a function in Python 3. Thus, doing print(...).format(...) is effectively trying to format the return value of the print() call, which is None.
Call .format() on the string you want formatted instead:
print("As so your name is {}, your quest is {} ".format(name,quest))
Your modified code was nearly right, you just needed to move a bracket to apply the % operator to the string instead of the print function result.
So change this:
print ("As so your name is %s, your quest is %s ") % (name, quest)
to this:
print ("As so your name is %s, your quest is %s " % (name, quest))
and it runs fine in Python 3.

why does this value get cut off?

So I'm trying to print out hex values in c++ using printf, and well, I want the output of the following string to be val:0x0366 including that leading 0
Here's the code
int poo = 0x00000366;
printf("val:0x%x \n",poo);
Here's the output:
0x366
Have you tried printf("val:0x%04x \n",poo);?
According to printf reference,
A format specifier follows this prototype:
%[flags][width][.precision][length]specifier
In your case:
%[0][4][default precision][default lenght]x

Am I missing something here ? XD TrimRight does not seem to want to work

Ok, here is the small portion of code to demonstrate:
CString txt = _T("Hello World");
CString txt2 = txt;
txt2.TrimRight('W');
AfxMessageBox(txt2);
The output is "Hello World".
What am I not getting right ?
The call txt2.TrimRight('W'); removes all characters 'W' from the right side of the string. Since "Hello World" does not end in 'W' nothing is trimmed at all.

Getting the longest string (ending by a newline) out of a Textarea in Flex

This somehow simple task is not so simple.
I can get the number of lines of the textarea using mx:internals, but thats is not always the longest line ending by a newline.
I tried all sort of textArea.text.split("\n") \r <br/> {/n ..
It always returns me the length of 1.
My eternal worshipping to anyone who can put me in the right direction.
Greg
==========
var arr:Array = texCodeArea.text.split(/\n/);
trace(arr.length);
trace("TEXT iS :", texCodeArea.text, "END");
==========
1
TEXT iS : aaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbb
cccccc END
Use /\r/ instead of /\n/.
Not sure why; it just works that way.
Try:
textArea.text.split(/\n/);
instead.
s.split(/\r\n/);

Resources