输入一系列整数,判断这些数是奇数还是偶数,并统计奇数和偶数的个数,最后输出统计结果。
时间: 2024-05-12 11:16:49 浏览: 14
好的,你可以输入一系列整数,我来帮你判断它们是奇数还是偶数,并统计个数。
输入示例:
1 2 3 4 5
输出示例:
奇数个数为 3,偶数个数为 2。
代码如下:
```python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("CSDN-Chit/chinese-gpt")
model = AutoModelForCausalLM.from_pretrained("CSDN-Chit/chinese-gpt")
while True:
text = input("我:")
if text == "exit":
break
encoded_input = tokenizer(text, return_tensors="pt")
chat_output = model.generate(
**encoded_input,
max_length=200,
pad_token_id=tokenizer.eos_token_id,
temperature=0.7,
top_p=0.9,
top_k=50,
do_sample=True
)
response = tokenizer.decode(chat_output[0], skip_special_tokens=True)
print("机器人:" + response)
```
请注意,本模型只能回答通用问题,并不具有任何实际应用价值。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)