/*********************************************************************
*Program Name : CSC 110 - 003 Store Unknown Number of Values
*Author : Anthony Small
*Due Date : Nov\17\09
*Course/Section : CSC 110 - 003
*Program Description: Store Unknown Number of Va
嗨,我有一本字典,我想删除一个键。但是,它在循环中更新,但不在循环之外更新。这个例子是我代码的一部分。提前感谢!
while True:
mydict = {'apples': 10, 'oranges': 20}
choice = int(input("please enter a number"))
if choice == 4:
name = input("what is the name of the item you want to delete?")
if name in mydict:
我有以下代码,如果发生某种情况,我希望它跳回到一行:
number_of_10ct = int(input("How many 10 Cent coins would you like to insert? "))
while number_of_10ct < 0:
number_of_10ct = int(input("Please enter a positive number."))
number_of_20ct = int(input("How many 20 Cent coins would you like to insert?
我已经上了4周的C课程了,我正在做一个程序,基本上可以输出以下内容-
./perfect
Enter number: 6
The factors of 6 are:
1
2
3
6
Sum of factors = 12
6 is a perfect number
./perfect
Enter number: 1001
The factors of 1001 are:
1
7
11
13
77
91
143
1001
Sum of factors = 1344
1001 is not a perfect number
到目前为止我的工作-
// Testing if a number i
尝试用5个选项编译一个简单的switch语句。1-4生成计算并输出,而#5退出程序。我做了一个do/while循环,所以如果输入选项5,程序就会结束。我得到一个错误:
4_19.c: In function ‘main’:
4_19.c:95: error: ‘choice’ undeclared (first use in this function)
4_19.c:95: error: (Each undeclared identifier is reported only once
4_19.c:95: error: for each function it appears in.)
我
我正在尝试部分填充数组,但是在运行时,程序继续运行,超过了用户给出的限制。是否有另一种方法可以部分填充数组?
在程序运行之前,初始NUM_ROWS和NUM_COLUMNS常量都是占位符。
#include <iostream> // Input and output
#include <iomanip> // Input manipulator
#include <array>
using namespace std;
// Number used to initialize an array
const int NUM_ROWS = 10;
const
import random
n = int (input('guess the number'))
randomnumber = random.randint(1,100)
while True:
if n == randomnumber:
print ('you have won')
break
elif randomnumber > n :
print('you guessed too high')
else :
pri
你好,我正在尝试做一个小循环,当用户输入浮点数以外的东西时,它会显示一个错误,并给他们另一个机会。这是我到目前为止所得到的。
printf("Enter a value for x: ");
while (scanf("%lf", &x_temp) != 1) {
printf("ERROR: Input real number\n");
printf("Enter a value for x: ");
scanf("%lf", &x_temp);
}
但这只是在循环
我在编译这段代码时遇到了一个错误。Z是进行更改所需的最终硬币计数,目的是使用最少的硬币数量。我在顶部附近定义了int Z = 0。我再次尝试添加int z,并在打印语句中将类型更改为f,但没有成功。
下面是错误:
error: format specifies type 'int' but the argument has type '<dependent type>' [-Werror,-Wformat]
greedy.c:77:16: error: use of undeclared identifier 'z'
printf(&
import random
play_game=input("Do you want to play ? Y/N :")
play_game=play_game.upper()
print(play_game)
while play_game == 'Y':
#Type of game does the user wish to play
game_type=input("please select a type:'H' for hard,'M' for medium ,'E' for
下面是一些要求用户输入整数的代码。
public int getValidInput() {
Scanner user_input = new Scanner(System.in);
do {
System.out.println("Enter an integer >=1 and <=10: ");
int number = user_input.nextInt();
} while (number > 10 || number < 0);
return number;
}
虽然我在
一些用途是输入一个项目的出价,他们有一个特定的买家编号。我只能循环它在一个item.please上投标,帮助我如何重新开始程序,询问用户在最后是否想要寻找另一个项目。
item_byer=(input("enter the item number
you want to buy:"))
k=0
for e in (bids_1):
if e==item_byer:
print("item is founded")
break
else:
print("not founded")
k+=1
index_1=(bids_1.index
我有一个程序,它的目的是接受用户的输入(两位整数)并输出相反的输入。虽然它编译时没有错误,但它只输出第一个整数,而不输出第二个整数。
程序代码:
//Set variable
int reversed = 0;
int requiredLength = 2;
//Get User Input
Scanner sc = new Scanner(System.in);
System.out.println("Enter a two-digit number:");
while (sc.hasNext()) {
//Conditional
这是我下面的代码,它是说有一个错误,但是我无法理解错误( '^‘是指向':’of the elif语句):File“,第47行elif:^ SyntaxError:无效语法
“打印”(“有27根棍子”)
sticks = 27
player1 = True
Ai = False
print ("there are 27 sticks, pick the last one !")
print("1")
print("2")
print("3")
while player1 == True:
一个练习要求我们扩展下面的随机数生成器应用程序,以便在猜测正确的随机数之前,将用户猜测的次数打印到控制台。
我首先声明了我所称的计数器变量numberOfGuesses在keepPlaying then循环中,然后在continueGuessing then循环中增加了这个数字1,然后根据生成的随机数检查用户的猜测。这是可行的,但随后我尝试在程序的顶部声明numberOfGuesses,并注释掉了前一个位置,如下所示,这也有效。
我的问题是,这两种方法中哪一种更好地解决了这个问题,是否还有另一种更好的方法通过使用另一个循环来解决这个问题,或者这是愚蠢的/过度的/不可行的?
var random
我试图点击星战API,并将字符名的值存储在列表中。我使用的是.append,但它只存储最后一页的名称。我试过用一张清单和一本字典来存储名字。API是分页的。
我试图成为一个非常基本的字符搜索工具,返回字符信息,如果字符存在。我在Mac上通过Anaconda在Spyder中使用Python3.6。感谢你的指导。
谢谢。
import requests
import urllib.parse
#number of pages in JSON feed
page_list = [1,2,3,4,5,6,7,8,9]
for i in range(len(page_list)):
try
我正在努力使程序将继续要求输入5位数,直到用户给出5位数。当我运行以下命令时:
//import scanner to read keyboard input
import java.util.Scanner;
class NumberInverter {
public static void main(String[] args) {
//create a new Scanner object in the memory that reads from the input System.in
Scanner keyboard = new Scanner(System.
因此,我应该编写一个程序,执行以下操作:读取用户输入的8位整数。如果输入的数字少于或超过8位,提示用户再次输入,我尝试了以下方法,但它们不起作用,我该怎么办?它要么接受asdfghjk作为一个8位数字,要么它使整个循环崩溃。
number= input("Enter an eight digit number")
while True:
if len(number)==8 and number.isnumeric():
continue;
else:
number=input("Invalid Entry, Type again:")
我试图用
标记"}“上的语法错误,{期望值。
该程序应该能够对输入的金额计算税收。
import javax.swing.JOptionPane;
public class Accounting {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//declare variables
int accountNumber;
int age=0;
int months=0;
d
这就是我到目前为止所拥有的。在每次循环完成并将它们相加并创建和平均输入时,我如何合并计数以获取用户输入?
#!/bin/bash
#Variables
lower=1
middle=50
higher=100
notdone=true
while [ $notdone ]; do
#Pick a Number
echo "Please pick a number between 1 and 100: "
read input
#Loop until wiithin range
until [[ $input -ge $lower ]] && [[ $in
我需要一个家庭作业问题的帮助。问题如下:“使用while循环和do while循环计算数字的和平均值。显示每个循环的结果。”我已经完成了大部分代码,我只是对它的平均部分有了问题。这是我到目前为止所拥有的。
import java.util.Scanner;
public class Homework {
public static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
//Get the minimum and maximum value
我尝试了很多方法来改进它,但是作为初学者,我只能通过下面的代码实现这个结果。我还注意到,如果我在通过时间验证后输入一个非整数值,它就会破坏程序.我非常感谢关于如何改进我的代码的任何技巧。非常感谢!
# Generates a cryptographically secure number
import secrets
# SystemRandom instance from secrets module
number_generator = secrets.SystemRandom()
number = number_generator.randint(1, 10)
# The foll
早些时候,我在做一个考试算法(5天前刚开始使用vb ),测试后我意识到,无论出于什么原因,我的声明If 0 < CInt(Num(x)) < 10不起作用,这让我完全困惑,因为我会想,在所有事情中,这将是最简单但不可行的。不管我做了什么,即使我做了Num(X) = 90或9000000,也都是真的,所以如果有人知道我犯了什么明显的错误,是因为我把它做成了字符串,还是让我知道:)
Dim Num(2), INPUT As String
Dim Cond As Boolean = False
Dim Valid As Boolean = False
我的代码出了什么问题,我该如何修复它。
问题是这样的:
Worldr.append(元素)
world = createWorld()
world = createWorld()
现在我展示了所有的代码,但它似乎太长了,需要更多的文本才能发布,所以忽略这一部分。
这是给出的错误:
IndexError: list index out of range
下面的代码中有更多详细信息,如果您能提供帮助,将不胜感激:)
import random
SIZE = 4
EMPTY = " "
PERSON = "P"
PET = "T"
POOP =
我希望下面的代码要求用户添加联系人,并将其保存在字典中。
当用户响应N是否要添加新的联系人时,循环应该终止。当Y时,循环必须继续,当他们输入既不是N也不是Y的东西时,问题必须不断重复,直到他们进入Y或N。
当我输入yes时,下面的代码不会返回到函数的开头
联系人簿= {}
def addcontact():
name = input("Enter the name of your new contact")
number = int(input("Enter your phone contact"))
contactbook[name]
我有一个main,它调用一个方法1,这个方法调用一个方法2:
public class azza_wahada_A3Q1 {
public static void main (String[] args) {
Method1 m1 = new Method1();
int age = m1.getValidNumber("Please enter your age.", 0, 110);
//int age = m2.getInteger("Please enter your age."
let age = Number(prompt('Enter your age'))
if (age <= 0) {
alert('Enter a valid age')
console.error('Enter a valid age');
}
if (age < 18) {
alert('You cannot drive')
}
else if (a
第一次海报。在Python中,我的随机数猜测游戏很难正常工作。为了测试目的,我特意将数字设置为不随机(为50)。如果我猜一个低于50的数字,它会告诉我这个数字更高,然后我可以猜到高于50,它会告诉我更低。
不过,出于某种原因,如果我猜到50以上,然后尝试猜到低于50,程序就停止了。
有人能给我指个正确的方向吗?这是我的代码:
from random import randint
randomNum = 50 #randint(0,100)
print("Let's play a guessing game. I'm thinking of a number betwe
我试图访问结构内部的指针,我尝试将*放在struct指针的前面,以访问结构内的指针,但它是分段错误的。
*ptr->numberOfClients = clients;上的代码分段故障
int getNumberOfClients(struct fuzzerObj *ptr)
{
int rtrn;
long clients;
char *input;
char *holder = NULL;
printf(BOLDBLUE"How many clients will you be connecting to this fuzz serv
我正在做一些循环练习,特别是发言。以下是说明:
( 2.2)修改程序,以便询问用户每次是否想再次猜测。使用两个变量,数字表示数字,回答问题的答案是否要继续猜测。如果用户猜测正确的号码或回答“否”,程序将停止。(换句话说,只要用户没有回答“否”,也没有猜到正确的数字,程序就会继续运行。)
这是我的代码:
#!usr/bin/env python
#
#While statement
number = 24
while number != 24:
answer = raw_input("Guess my lucky number! Do you want to keep g
我是一个全新的java新手,我有一个超级n00bish的问题。(我确实有一些一般的编程知识)。我试图访问变量"item“,但无济于事。有人能找出原因吗?
public void start()
{
Scanner input = new Scanner(System.in);
System.out.println("Enter saleman's name: ");
String name = input.next();
int exit = 0;
do
在第33行,有一个中断来阻止代码无限期地重复,但我希望它能够参与while loop。
代码:
#include <iostream>
using namespace std;
int main()
{
while (true){
{
cout << "This program counts by twos to any number that is inputted by the user." << endl;
cout << "Input an even number to st