头哥练习6-3:恺撒加密第2步(小写转大写)
时间: 2024-01-08 08:02:56 浏览: 201
恺撒加密的第2步是将明文中的小写字母转换为大写字母,具体实现可以用Python的内置函数`upper()`来实现。例如:
```python
plaintext = 'hello world'
ciphertext = plaintext.upper()
print(ciphertext)
```
运行结果为:
```
HELLO WORLD
```
其中,`plaintext.upper()`将`plaintext`中的小写字母转换为大写字母,得到密文`ciphertext`。
相关问题
练习6-3:恺撒加密第2步(小写转大写)
恺撒加密的第2步是将明文中的小写字母转换为大写字母。可以使用Python中的upper()方法来实现这个功能。示例代码如下:
```
plaintext = "hello world"
ciphertext = ""
for char in plaintext:
if char.islower():
char = char.upper()
ciphertext += char
print(ciphertext)
```
输出结果为:
```
HELLO WORLD
```
这样就完成了恺撒加密的第2步,将明文中的小写字母转换为大写字母。
练习6-3:恺撒加密第2步(小写转大写) C++C++
以下是小写字母转换为大写字母的C++代码实现:
```cpp
#include <iostream>
using namespace std;
int main() {
char ch;
cout << "请输入一个小写字母:";
cin >> ch;
if (ch >= 'a' && ch <= 'z') {
ch = ch - 'a' + 'A'; // 将小写字母转换为大写字母
cout << "转换后的大写字母为:" << ch << endl;
} else {
cout << "输入的不是小写字母!" << endl;
}
return 0;
}
```
运行程序后,按照提示输入一个小写字母,程序会将其转换为大写字母并输出。如果输入的不是小写字母,则程序会提示输入错误。