(填空题) 假设字典变量 dic_country 存储了部分国家的国家名与首都名的对应关系,其中国家名为键,首都名为值。试补充程序,实现根据用户输入的国家名查询首都名,如果存在则输出查询结果,否则提示“未查询到该国家名!”。 dic_country = {"China":"Beijing", "America":"Washington", "Norway":"Oslo", "Japan":"Tokyo", "Germany":"Berlin", "Canada":"Ottava", "France":"Paris", "Thailand":"Bangkok"} c=input("国家:").lower().__________ if ___________________: print("首都:{}".format(___________)) else: print("未查询到该国家名!")
时间: 2023-07-02 19:16:38 浏览: 187
```
dic_country = {"China":"Beijing", "America":"Washington", "Norway":"Oslo", "Japan":"Tokyo", "Germany":"Berlin", "Canada":"Ottava", "France":"Paris", "Thailand":"Bangkok"}
c = input("国家:").lower().strip()
if c in dic_country:
print("首都:{}".format(dic_country[c]))
else:
print("未查询到该国家名!")
```
注:代码中 strip() 方法可以去掉用户输入字符串两端的空格,lower() 方法可以将字符串转换为小写字母,这样即使用户输入的是大小写混合或者首字母大写的国家名,也能正确匹配字典中的键。
相关问题
vue2中填空题需要再富文本_下划线中填写数据该如何解决
在Vue2中,可以使用第三方富文本编辑器插件来实现填空题的编辑和展示。常用的富文本编辑器插件有Quill、Tinymce和Vue-Quill-Editor等。
在使用富文本编辑器插件时,可以在编辑器中添加下划线(或其他标记)来标识填空题,然后在保存或提交数据时,解析富文本内容,提取填空题的答案并进行处理。
例如,使用Vue-Quill-Editor插件,可以在编辑器中添加下划线,并使用正则表达式提取填空题的答案,示例代码如下:
```javascript
<template>
<div>
<quill-editor v-model="content" ref="myQuillEditor"></quill-editor>
<button @click="submit">提交</button>
</div>
</template>
<script>
import Quill from 'quill';
import 'quill/dist/quill.snow.css';
import { quillEditor } from 'vue-quill-editor';
export default {
components: {
quillEditor
},
data() {
return {
content: ''
}
},
methods: {
submit() {
const regex = /_(.*?)_/g; // 提取下划线中的内容
const matches = this.content.matchAll(regex);
for (const match of matches) {
const answer = match[1]; // 填空题答案
// 处理填空题答案
}
}
}
}
</script>
```
4.代码填空,实现引用名为"main.css"的外部样式表: (2.0分
```html
<link rel="stylesheet" href="main.css">
```