while-loop

Need to create a program that prints out words starting with a particular letter

别说谁变了你拦得住时间么 提交于 2019-12-24 18:22:57
问题 I need a program that asks the user for 3 letters then asks the user for a string, then prints out all words in the string that start with the three letters...e.g Enter 3 letters: AMD Enter text: Advanced Micro Devices is a brand for all microsoft desktops word: Advanced Micro Devices word: all microsoft desktops it's pretty simple. I'm new and having trouble figuring out how...my code is currently... ipt1 = raw_input("Three letters: ") ## Asks for three letters ipt2 = raw_input("Text: ") ##

Else If and Do while does not work as intended

家住魔仙堡 提交于 2019-12-24 16:09:28
问题 EDIT: Recent happenings of me compiling a program I know could not compile lead me to believe I am simultaneously having an issue with my compiler. No doubt due to my running it in WINE on mac as opposed to a native application. Thank you for your responses. I will properly test out all responses and make all changes when I have fixed said error with compiler or I have moved computers to one with a working one. I am relatively new to programming and also this website so please bear with me. I

else statement does not return to loop

筅森魡賤 提交于 2019-12-24 15:25:56
问题 I have a code that opens a file, calculates the median value and writes that value to a separate file. Some of the files maybe empty so I wrote the following loop to check it the file is empty and if so skip it, increment the count and go back to the loop. It does what is expected for the first empty file it finds ,but not the second. The loop is below t = 15.2 while t>=11.4: if os.stat(r'C:\Users\Khary\Documents\bin%.2f.txt'%t ).st_size > 0: print("All good") F= r'C:\Users\Documents\bin%.2f

Bash while loop to compare two files and print line number

▼魔方 西西 提交于 2019-12-24 14:24:57
问题 I have file1: A B C D I have file2: B C I want to use a while read loop to go through both files compare them and print out the line number of file1 for any matching lines. COUNT=0 while read line do flag = 0 while read line2 do COUNT=$(( $COUNT + 1 )) if ( "$line" = "$line2" ) then flag = 1 fi done < file1 if ( flag -eq 1 ) then echo $COUNT > file3 fi done < file2 However I get an error: B command not found Please could someone let me know where I have gone wrong. Thanks. 回答1: There are

How do I move to the next index?

感情迁移 提交于 2019-12-24 14:07:21
问题 I have a list of different monetary notes and I want to jump to the next index after each loop. How can I do that? I want to make the str dividor equel to [1] after the first loop, then [2], then [3] etc. money_list = [100,50,20,10,5,1,0.5] dividor = money_list[0] while change>0.5: print (change/100) + " X " + [0] change dividor + [0] 回答1: You either need to store the current index in a variable: money_list = [100,50,20,10,5,1,0.5] cur_index = 0 while change>0.5: print (change/100) + " X " +

PHP MYSQL SET gives error in while loop

拜拜、爱过 提交于 2019-12-24 13:48:15
问题 I have this query: $result2 = mysql_query("SET @total=0; SELECT *, @total:= @total+ `companyearned` AS `total` FROM `recordedhours` WHERE `group` = '$uid' ORDER BY `unixdate` DESC, `idnum` DESC LIMIT $from, $max_results"); while ($rowb = mysql_fetch_array($result2)) { //DO STUFF } But the SET @total=0; makes the while line give me an error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in The query works fine in phpmyadmin and the while works fine

Exiting a method with a specific string

本秂侑毒 提交于 2019-12-24 12:45:46
问题 I'm still relatively new at Java and am working on a program for class. I have everything coded up and it's working great, but I need to exit a method when I type the string "exit". My current code will be below. I must have 3 methods (includes main) and a "while" loop (or do-while, but my professor has barred us from using those) as per the assignment. It's a "magic eight ball" program and the while loop is set to continue asking questions until the user types "exit" but I can't seem to get

How do I do two MYSQLI queries in one page, what is the best method

天大地大妈咪最大 提交于 2019-12-24 12:19:20
问题 All right. I'm learning about the mysqli API. I've got two files. One that connects to my database, and one that runs the query. Everything works. However, I want to run two queries in a single page. How can I do this? What is a good method to do this? Would the best way be to include my db connect once, then run both queries, and then close my connection to my db once ending it all together? Is that how most people do it? db.php $mysqli = new mysqli("..", "..", "..", ".."); /* check

Program stucks in infinite loop although there is a condition to terminate it: MATLAB

偶尔善良 提交于 2019-12-24 11:50:08
问题 I'm building a program that fills a hollow cube with many small cubes. Then, makes a connected path through random cubes. The path is found step by step by looking at the direct neighbors of each cube and select anyone of them as the next step. To illustrate, The following picture shows the path that consists of cubes (red cubes), To build the path I started form some cube, colored it with red, found its neighbor cubes (6 neighbors because we have 6 faces), selected any of them randomly,

python 3.2 global variable not updating when its in a thread

瘦欲@ 提交于 2019-12-24 11:44:44
问题 I'm making a program and I got into a problem. I have a thread running which has a while loop that checks if a global variable is equal to False, if its equal to True then exit the while loop. The problem is even if i update the global variable to True it still doesn't stop, it just continues on. Code: While loop: while stopIt==False: print(stopIt) # Always prints out False, even when exit() is called # do things... Stopper: def exit(): stopIt = True stopIt variable defenition: global stopIt