小编Csc*_*319的帖子

生成一个rand()%25,其中每个数字只能出现一次

我正在尝试使用数组来修正一个程序,它可以获得0到24之间的随机数,但它们只能出现一次.我知道如何生成随机数,我只是坚持如何检查数字中是否已存在数字.我尝试生成一个新的rand()%25并将其与数组中的占位符进行比较,如果它不存在则将新的随机数放在那里,但它不起作用.

 void MultiU (){
         int size = 5;
         int array[5];
        srand(time(0));

        for (int index = 0; index < size; index++){
           exists[index] = rand() %25;
          }
    }
Run Code Online (Sandbox Code Playgroud)

我是使用数组和rand()进行编程的新手.我希望有人可以指导我朝着正确的方向前进.

c++ arrays

0
推荐指数
2
解决办法
1457
查看次数

AttributeError:'bool'对象没有属性'count'

我是Python的新手,我正在编写下面的代码.

fileName = input("Enter the file name: ")
InputFile = open(fileName, 'r')
text=InputFile.readable()

sentences = text.count('.') + text.count('?') + \
            text.count(':') + text.count(';') + \
            text.count('!')
Run Code Online (Sandbox Code Playgroud)

由于下面的错误,我无法通过计数功能.我做了一些研究并尝试导入一些库,但这没有用.有人能引导我朝正确的方向发展吗?我感觉很失落.

 text.count(':') + text.count(';') + \
AttributeError: 'bool' object has no attribute 'count'
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
1
解决办法
830
查看次数

标签 统计

arrays ×1

c++ ×1

python ×1