到目前为止,我所拥有的是
import random
def go():
rounds = 0
while rounds < 5:
number = random.randint(1, 5)
if number == 1:
print('a')
elif number == 2:
print('b')
elif number == 3:
print('c')
elif number == 4:
print('d')
elif number == 5:
print('e')
rounds = rounds + 1
go()
Run Code Online (Sandbox Code Playgroud)
并且输出结束了生物的某些东西
e
e
c
b
e
Run Code Online (Sandbox Code Playgroud)
如何制作一个数字只使用一次,字母不重复?(例如某事)
a
e
b
c
d
Run Code Online (Sandbox Code Playgroud)
提前致谢
我试图弄清楚如何能够读取 .txt 文件作为命令提示符参数而不是用户输入。如果我有程序
#include <iostream>
#include "cmdline.h"
using namespace std;
int main (int cnt, char * args[]) {
int a = cmdline_int(args, 1);
int b = cmdline_int(args, 2);
cout << "sum = " << a << " + " << b << " = " << a + b << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
其中文件“cmdline.h”包含
#include <cstdlib>
#include <string>
using namespace std;
int cmdline_int( char* cmdline_a[], int n ) {
return atoi( cmdline_a[ n ] );
}
char cmdline_char( char* …Run Code Online (Sandbox Code Playgroud) 我对Python(以及一般的编程)相当陌生,我想知道是否有办法在同一时间运行2个或更多while循环,以便在每个循环的每一轮之后切换到另一个循环,而不必重新开始在零回合.这是我到目前为止所拥有的:
def loop1():
rounds = 0
while True:
if rounds == 1:
print('A')
elif rounds == 2:
print('B')
else:
rounds = 0
rounds = rounds + 1
def loop2():
rounds = 0
while True:
if rounds == 1:
print('a')
elif rounds == 2:
print('b')
else:
rounds = 0
rounds = rounds + 1
loop1()
loop2()
Run Code Online (Sandbox Code Playgroud)
现在,当我这样做时,它所做的就是无限地运行loop1()并且永远不会进入loop2(),但是我想知道一种方法来获得输出:
A
a
B
b
A
a
B
b
A
a
... and so on.
Run Code Online (Sandbox Code Playgroud)
谁知道我怎么做到这一点?
另请注意,我是初学者,并没有真正涉及所有的编程术语,所以请使用小词:)提前谢谢.(我也在使用Python 3(虽然我认为你可能已经知道了吗?))
所以我正在编写这个程序来执行一个基本任务菜单,其中一个是告诉用户输入的字符是大写,小写还是不是字母.
#include <iostream>
using namespace std;
int main () {
int mi;
cout << "1) Area of Circle" << endl;
cout << "2) Character Detection" << endl;
cout << "3) Capitalization 1-3-5" << endl;
cout << "4) Binomial Roots" << endl;
cout << "0) Quit" << endl;
cin >> mi;
switch (mi) {
case 2:
{
char c;
cout << "input a character: ";
cin.get(c);
cin.ignore(); /////// unsure if using this properly
if ('a' <= c && c <= 'z') …Run Code Online (Sandbox Code Playgroud)