所以,我正在研究一个掷骰子程序模拟器,从浏览网页,以及来自这个论坛上的用户的一些帮助.我能够在大多数情况下完成它.至少,我认为我有正确的游戏逻辑.
它是我上次使用它时运行但是我必须在没有意识到它的情况下改变了一些东西,因为现在while循环正在运行.在该计划中,骰子在没有用户干预的情况下永远滚动.
有人可以看一看,看看代码是否有问题?我已经在这个工作了几个小时,没有在哪里.
我再也不会赌博了!:/
from Dice import PairOfDice
print("Now Let's play with two dice!")
#
def MainDouble():
bdice = PairOfDice()
doubleDiceRoll = ''
global myPoint #declare global variable
input("Press Enter to Roll the Dice once")
while doubleDiceRoll == '': #Roll the dice (both die objects)
bdice.toss()
print ('The first die reads.. ' + str(bdice.getValue1()) + '\n')
print ('The second die reads.. ' + str(bdice.getValue2()) + '\n')
Val = bdice.getTotal()
##Beginning of conditional blocks##
if Val == 7 or Val == …Run Code Online (Sandbox Code Playgroud) 当程序进入第二个循环时,即使我将第二个循环的值设置为false,它也会变为无限.问题出在哪里?第一个while循环我从来没有遇到任何问题退出,但第二个...我只是看不到在哪里或为什么.
int RareData::assignRareType()
{
int switchType;
std::cin >> switchType;
bool valid = true;
bool valid2 = true;
while (valid)
{
switch (switchType)
{
case 0:
std::cout << "1 - Character Change\n2 - Account Change\n3 - Both\n";
int switchData;
std::cin >> switchData;
valid2 = true;
while (valid2)
{
switch (switchData)
{
case 1:
valid2 = false;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
assignCharacter();
break;
case 2:
valid2 = false;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
assignAccount();
break;
case 3:
valid2 = false;
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
assignAccount();
assignCharacter(); …Run Code Online (Sandbox Code Playgroud) 我刚刚开始在TCL中编码,并且有这个while循环代码:
set x 0
while "$x < 5" {
set x [expr {$x + 1}]
if {$x > 7} break
if "$x > 3" continue
puts "x is $x"
}
puts "exited second loop with X equal to $x"
Run Code Online (Sandbox Code Playgroud)
哪个输出:
x is 1
x is 2
x is 3
exited second loop with X equal to 8
Press any key to continue . . .
Run Code Online (Sandbox Code Playgroud)
这绝对令我困惑.我好奇,会"$x > 3"被评估为好像[expr {"$x > 3"}]或好像(这是一个字符串,因为它只是一个字符串本身就是真的.)
它是如何工作的?给我机械师.巨大的偏头痛试图解决这个问题.
我在Ada83中编写了以下代码来查找文件的大小:
with Text_IO;
use Text_IO;
procedure imp3ada is
package Int_IO is new Text_IO.Integer_IO(Integer);
use Int_IO;
inputFile: File_Type;
i: integer:=0;
fileSize: Integer:=0;
fileCurrentPosition: Integer:=0;
begin
open(inputFile, In_File, "test.cfg");
while not End_of_File(inputFile) loop
fileCurrentPosition:=fileCurrentPosition+1;
end loop;
fileSize:=fileCurrentPosition;
Int_IO.put(fileCurrentPosition);
Int_IO.put(fileSize);
close(inputFile);
end imp3ada;
Run Code Online (Sandbox Code Playgroud)
代码编译得很好,但是当我尝试运行时没有任何反应,我希望它能够打印文件中的字符数.我猜它会进入无限循环.有人可以帮助我解决它出错的地方吗?
我有一个名为Training的表,其中包含Employee ID,Hours,is3ManDay等行.在此表中,可能有多个记录对应于同一个Employee.
我必须计算与每个员工ID相关的小时数,我这样做了
SELECT EMP_ID, SUM(HRS) AS TOTALHRS, is3ManDay
from Training
GROUP BY EMP_ID, is3ManDay
Run Code Online (Sandbox Code Playgroud)
工作完全正常,但现在我想根据每个员工的总小时数将is3ManDay更新为是或否
@Emp_ID int,
@is3ManDay varchar(10)
IF (SELECT SUM(Hrs) FROM Training WHERE Emp_ID = @Emp_ID) >= 36
BEGIN
UPDATE Training
SET is3ManDay = 'Y'
Where Emp_ID = @Emp_ID
END
ELSE
UPDATE Training
SET is3ManDay = 'N'
Where Emp_ID = @Emp_ID
Run Code Online (Sandbox Code Playgroud)
这个也很好但是我必须手动更改@Emp_ID并执行不实用的存储过程.我想在这段代码中包含一个循环,但如果我删除@Emp_ID,它将更新所有具有相同值的行,因为没有选择ID.
WHILE (SELECT SUM(HRS) FROM Training) >= 36
BEGIN
UPDATE Training
SET is3ManDay = 'Y'
END
Run Code Online (Sandbox Code Playgroud)
我尝试了WHILE声明,但没有为我工作.
我完全迷失了,不知道如何甚至说出这个问题.我有一个循环,如下所示.如果if循环中的语句证明为true,indexPath则为其分配一个值,循环完成(_samplePictures数组中有49个对象)并输入if (found)然后加载找到的数据.如果条件不正确并且没有找到任何内容而不是进入if(!found)应用程序崩溃.我已经尝试了这种当前编码方案的各种结构.我甚至删除了循环并进入了if(!found)它应该做的事情.(ooooodddddddd)
此语句位于其viewDidLoad正上方(if语句不是viewDidLoad)是一个if确定内容的语句_samplePictures.
知道数组中的图像是这样定义的可能是有用的:
#define IMG_71 [UIImage imageNamed:@"imagename.jpg"]
Run Code Online (Sandbox Code Playgroud)
数组的结构是这样的:
_samplePictures = @[@{@"Image": IMG_71, @"Title" : @"title of item", @"Description" : @"complete description of item"}];
if (fromKitInstructions)
{
int i = 0;
NSIndexPath *indexPath;
found = FALSE;
while(i <= _samplePictures.count)
{
if([_samplePictures[i] objectForKey:@"Title"] == instructionName)
{
indexPath = [NSIndexPath indexPathForRow:i inSection:0];
i = 50;
found = TRUE;
}
else
{
i++; …Run Code Online (Sandbox Code Playgroud) 嗨,我正在练习java,只学习java几天.我需要减去500000的奖学金金额100000,但我似乎被困在400000并且它不会继续.我的代码有什么问题请有人帮助我.提前致谢.
import java.util.Scanner;
import java.util.LinkedList;
public class Main
{
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);
Application a = new Application();
LinkedList lList = new LinkedList();
boolean bEligible = false;
int scholarship = 100000;
int scholarshipAmount = 500000;
int amount;
while(scholarshipAmount != 0)
{
System.out.println("Please enter name");
a.setsName(input.nextLine());
System.out.println("1–Pre Diploma, 2–Diploma, 3–Degree");
System.out.println("Please enter your Study Level");
a.setiStudyLevel(input.nextInt());
System.out.println("Please enter your Personality Score");
a.setiPersonalityScore(input.nextInt());
System.out.println("Please enter your Parents Incomee");
a.setdParentsIncome(input.nextDouble());
String sName = a.getsName();
int …Run Code Online (Sandbox Code Playgroud) 我想确保输入数字.我已尝试使用符号和字母进行测试,但shell只会抛出一个错误,上面写着"Decimal的文字无效".我正在研究计算器,所以认为十进制模块最适合.提前致谢.
这是我的代码:
import decimal
while True:
userInput = (raw_input("Enter number:"))
try:
userInput = decimal.Decimal(userInput)
break
except ValueError:
print ("Number please")
Run Code Online (Sandbox Code Playgroud)
使用Python 2.7.6
我正在制作一个while循环计数器,我想跳过某个数字,这些数字的值+ 10,+ 20,+ 30 ......等等.这是我到目前为止所尝试的:
lstLength = 26
skipNum = [2, 8]
lst = []
count = 0
while len(lst) < lstLength:
count +=1
if count == skipNum[0] or count == skipNum[1]:
continue
lst.append(count)
print(lst)
Run Code Online (Sandbox Code Playgroud)
我希望结果列表长度为lstLength,同时跳过数字2,8,12,18,22,28,32,38等等......我怎么能这样做?谢谢!
我在创建与mysql数据库行对应的一堆东西的代码时遇到了麻烦.它需要继续创建内容,直到使用所有行然后停止.
当前存在的行数为5
但由于某种原因,php文件导致浏览器继续加载(它永远不会结束).任何帮助,将不胜感激!谢谢!
问题不在于这个PHP文件,而是在我的HTML代码中,感谢大家的帮助
<?php
mysql_connect ("localhost", "root", "") or die ("We couldn't connect!");
mysql_select_db ("dr");
mysql_query ("SELECT * FROM songs");
$result = mysql_query ("SELECT * FROM songs");
while ($row=mysql_fetch_array($result)) {
$name = $row ['songname'];
$genres = $row ['songgenres'];
$mediafire = $row ['mediafirelink'];
$dropbox = $row ['dropboxlink'];
$source = $row ['audiosource'];
echo "
<div class='playing'>
<!-- ======== Song Name ======== -->
<li class='songnameli' id='$source'>
<span class='info'>$name</span>
<audio>
<source src='music/singles/$source.mp3'>
<source src='music/singles/$source.ogg'>
</audio>
</li>
<!-- ======== Playlist ======== -->
<li class='playlistli'> …Run Code Online (Sandbox Code Playgroud) while-loop ×10
python ×3
if-statement ×2
ada ×1
c++ ×1
count ×1
database ×1
file-io ×1
forever ×1
ios ×1
java ×1
list ×1
loops ×1
mysql ×1
objective-c ×1
php ×1
python-2.7 ×1
sql ×1
sql-server ×1
t-sql ×1
tcl ×1
user-input ×1