My program contains quite a lot so I'm not going to bore you with the details, if there are any other problems that you spot which I haven't, you don't need to point them out unless you have a serious case of OCD. Here is the parts of the program relevant to the question I'm asking.  def LettersIntoCode():     cluesFile = open("clues.txt", 'r+')     cluesLines = cluesFile.readlines()     cluesFile.close()     clues = {}     for line in cluesLines:         clues[line[1]] = line[0]     CodedFile = open('words.txt')     print()     for line in CodedFile:         ***WordsWithChanges = (''.join(clues.get(c,c) for c in line.strip('\r\n')))***         print(WordsWithChanges)     CodedFile.close()  def GameCompletion():     SolvedFile = open("solved.txt", 'r')     ***while WordsWithChanges != SolvedFile***:         MenuChoice()     SolvedFile.close()   When called upon this error pops up:      while WordsWithChanges != SolvedFile: NameError: global name 'WordsWithChanges' is not defined   Now don't worry about anything else but the Bold and Italic although you may find the other stuff useful for understanding purposes. I've tried putting inglobal WordsWithChanges but as most will know that didn't work, thanks for your co-operation, if you need anything just ask!
4613
How can I create or use a global variable in a function?  If I create a global variable in one function, how can I use that global variable in another function? Do I need to store the global variable in a local variable of the function which needs its access?
16574
This is probably a really basic question:  When I write code, I want to achieve a logical and readable structure of the lines, where I can see which brace closes which brace.  \begin{equation}  \begin{multlined}   Here is some random equation that goes on for a long time  \end{multlined} \end{equation}   If the equation (here I am referring to the source code, not the compiled document) goes on to where it needs to jump to the next line, it is left-aligned, which screws up the indentation. I can manually add some spaces, but then if I change the size of the window, it realigns and is wrong again. What is the right way to achieve a logical indentation?  My apologies if this has been asked before; I did not find it on previously asked questions.  Edit: Sorry, forgot to mention, I am using writelatex.com as my editor.
10915
I'm pretty new to coding and I want to get an opinion on my coding. I am learning Python and I made a really simple heads and tails guessing game.  import random import time import easygui import sys while True:     rand = random.choice(["Heads", "Tails"])     firstguess = raw_input("Guess Heads or Tails: ")     if firstguess == rand:         print "Wow you win"     else:         print "That is wrong you suck so bad lol."     time.sleep(2)     answer = easygui.buttonbox("Play again?", choices=["Yes","No"])     if answer == "Yes":         easygui.msgbox("Ok")     else:         break  easygui.msgbox("Ok, see you later!") sys.exit(0)
90301
Formatting breaks if code follows a list:   List item List item  This is in a code block  This does not work as expected   However, it works if between the list and the code   List item List item   There is a line of normal text.  This is in a code block # This does work as expected   Edit  To make this clear: This is not about nesting code in a list but about code following a (finished) list not working as expected (by me). To put it differently: Why is a list not considered finished despite of following empty lines? What do I have to do?
21221
If I do   $ cat &gt; file.txt      textCtrl-DCtrl-D   Question 1: If I don't press enter, why do I have to press Ctrl-D twice?  If I do  $ cat &gt; file.txt      pa bam pshhhCtrl-Z   [2]+  Stopped         cat &gt; file.txt $ cat file.txt $ cat &gt; file.txt      pa bam pshhh      Ctrl-Z   [2]+  Stopped         cat &gt; file.txt $ cat file.txt pa bam pshhh   Why is the second time the file with 1 line?
94156
Open a prompt, try to do this:   type this code: export PS1="\e[1;30m-30-\e[m &gt;" copy it with your mouse (select the code + copy it (I have auto-copy when I select with the mouse enabled)) close the prompt open a brand new prompt immediately paste it (SHIFT INS) type "HOME" key and "END" key, you'll see the cursor go to logical positions (start and end of the code) now press ENTER you prompt changes the colors immediately paste it (SHIFT INS) type "HOME" key and "END" key, you'll see the cursor go to illogical positions (offset problem)   This means if I apply colors to the prompt I can't copy/paste + change my copied code...   NB: I'm asking it here because I thought it was a problem of  but it seems it's only related to what I'm trying to assign: export PS1="\e[1;30m-30-\e[m &gt;"... and I dont see a problem. It should just change the colors of the prompt (and that's what it does actually). But it seems it does something more I dont see. Does somebody know what it could be?
32082
Is there a variant of cat that outputs syntax-highlighted lines of code when used on a source file?  An idea: maybe vi[m] or another editor can be asked to dump the syntax-highlighted contents of said files to stdout and exit immediately?
40363
I'm trying to replace each , in the current file by a new line:  :%s/,/\n/g    But it inserts what looks like a ^@ instead of an actual newline. The file is not in DOS mode or anything.  What should I do?  If you are curious, like me, check the question  as well.
16238
How do I escape a backtick ` within a code block?  This is probably a duplicate, since I'm sure it's a common concern, but I can't find a question that addresses this specifically.  How do I write List'1 with the "1" character still in the code-text format?
69933
For start, we know how can we output random lines from a txt file:   perl -MList::Util -e 'print List::Util::shuffle &lt;&gt;' words.txt   But we need a general solution (perl is usually installed on every unix-like OS) to output 4 random words from a txt file, how can we do it?    $ cat words.txt ... alpha beta gamma delta epsilon ... $   The "..." represents many other words.   Example output (without newline between them, but one unix newline is needed at the end, spaces should separate them):  $ perl SOMEMAGIC words.txt gamma alpha delta beta $   Using only perl, the shortest possible solution (oneliner).   It will be used as human memorable password generator:    Since afaik perl is enough good to be named "random generator".   Example common english wordlist with 32768 unique lines:
54589
I quite often get stuck trying to solve particular problems, or getting syntaxes right.   Apart from the details provided in the links on , does anyone know of any 3rd party resources/manuals explaining it in a bit more user friendly way?
83848
I am looking for a package that will allow me to write pseudocode  of algorithms. The pseudocode may include mathematical symbols, like \forall, \in and subscripts. But I would like also to "talk" about variables contained in the pseudocode in my text, so be able to say "In figure ... variable foobar corresponds .." and make the word foobar have the same appearance as in the pseudocode example.  I found that with the listings package I can add mathematical symbols by using: \begin{lstlisting}[mathescape]. The problem with this package is that I don't know how to make just one word have the same appearance as the words appearing inside \begin{lstlisting} ... \end{lstlisting}.  Any ideas how to do this?  Or perhaps of another package that will help solve the above mentioned problem?
100086
What's the difference between file and open in Python?  When should I use which one?  (Say I'm in 2.5)
24489
#include &lt;stdio.h&gt; #include &lt;conio.h&gt; main() {     char ch,name[20];     int i=0;     clrscr();     printf("Enter a string:");     while((ch=getch())!='\n')     {         name[i]=ch;         i++;     }     name[i] = '\0';     printf("%s",name); }   When I give "abc" as input and if I press enter it's not working. Can anyone let me know why the condition ch=getch() != '\n' is not becoming false when I press enter? I have also observed that ch is taking \r instead of \n. Kindly let me know. Thanks
85724
This code is part of a larger code that generates an Arithmetic Quiz, although the code I have show below just saves the score that the user got on the test and their name. When saving the code it checks if the user has taken the quiz before. If the user has taken the quiz before it saves it as 'Older Score' or 'Oldest Score', however if the user has not taken the quiz before it generates a new row for them. Additionally it works out the average score and highest score for all users it has the data for. For my task I'm supposed to make the code as short as possible.  name = ""+first_name+" "+last_name rows_data = [] class_file_names = ['Class 1.csv', 'Class 2.csv', 'Class 3.csv'] scan = open(class_file_names[int(math_class)-1], 'r+') rows = csv.reader(scan) for row in rows:     rows_data.append(row) scan.close() class_file_names=['Class 1.csv', 'Class 2.csv', 'Class 3.csv'] csvfile=open(class_file_names[int(math_class)-1], 'w', newline="") fieldnames = ['Student Name', 'Oldest Score', 'Older Score', 'Latest Score', 'Average', 'Highest'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() nameFound=False for x in rows_data[1:]:     if x[0] == name:         x[3]=x[2]         x[2]=x[1]         x[1]=str(score)         x[4]=(int(x[1])+int(x[2])+int(x[3]))/3         x[5]=max(x[1],x[2],x[3])         nameFound=True     writer.writerow({'Student Name': x[0], 'Oldest Score': x[3], 'Older Score': x[2], 'Latest Score': x[1], 'Average': x[4], 'Highest' : x[5]})  if nameFound==False:     writer.writerow({'Student Name': name, 'Latest Score': score, 'Older Score': '0', 'Oldest Score': '0', 'Average': score, 'Highest': score}) csvfile.close() input("Test complete! Press anything to close.")
48194
With the commands \openout and \write I output text into a file. I want this file to have a name of containing an underscore (eg. name_01.txt), but I'm unable to get the underscore in the filename. My attempt (with \_):   \documentclass{article} \begin{document} \newwrite\tempfile \immediate\openout\tempfile="name\_01.txt" \immediate\write\tempfile{this is interesting} \immediate\closeout\tempfile \end{document}
85770
I just spotted someone use \newcommand* in an answer and realised that I'd never quite sorted out in my head what the star (asterisk) was there for.  (This one is practically impossible to search for on the internet so this is a good place to record the answer!)