各位父老乡亲们,帮我看一下这个代码,就是运行不了,不知道哪里出错了

x=input("请输入一个整数")

s=x%2

if s==0:

print("{}是偶数。".format(s))

else:

print("{}是奇数。".format(s))

input函数接收到的数据默认都是字符串类型的,转换一下x=int(input("请输入一个整数"))

有帮助的话,请点采纳该答案~

x=input("请输入一个整数")
s= int(x)%2
if s==0:
    print("{}是偶数。".format(x))
else:
    print("{}是奇数。".format(x))


  • 这有个类似的问题, 你可以参考下: https://ask.csdn.net/questions/7638695
  • 这篇博客也不错, 你可以看下对简单梯度下降方法的分析总结,有关步长,梯度精度和迭代次数
  • 除此之外, 这篇博客: 多线程爬取表情包,斗图再也难不倒我了中的 代码 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 首先快速的导入我们需要的模块,我把相同的表情都放在了同一个文件夹下面,所以需要导入 os 模块

    import asyncio
    import aiohttp
    from lxml import etree
    import os

    编写主要的入口方法

    headers = {"user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"}
    async def get_face(url):
        print("正在操作{}".format(url))
        async with aiohttp.ClientSession() as s:
            async with s.get(url,headers=headers,timeout=5) as res:
                if res.status==200:
                    html = await res.text()
                    html_format = etree.HTML(html)
    
                    hrefs = html_format.xpath("//a[@class='list-group-item random_list']")
    
                    for link in hrefs:
                        url = link.get("href")
                        title = link.xpath("div[@class='random_title']/text()")[0]  # 获取文件头部
    
                        path = './biaoqings/{}'.format(title.strip())  # 硬编码了,你要先在项目根目录创建一个biaoqings的文件夹
    
                        if not os.path.exists(path):
                            os.mkdir(path)
                        else:
                            pass
    
                        async with s.get(url, headers=headers, timeout=3) as res:
                            if res.status == 200:
                                new_html = await res.text()
    
                                new_html_format = etree.HTML(new_html)
                                imgs = new_html_format.xpath("//div[@class='artile_des']")
                                for img in imgs:
                                    try:
                                        img = img.xpath("table//img")[0]
                                        img_down_url = img.get("src")
                                        img_title = img.get("alt")
                                    except Exception as e:
                                        print(e)
    
                                    async with s.get(img_down_url, timeout=3) as res:
                                        img_data = await res.read()
                                        try:
                                            with open("{}/{}.{}".format(path,img_title.replace('\r\n',""),img_down_url.split('.')[-1]),"wb+") as file:
                                                file.write(img_data)
                                        except Exception as e:
                                            print(e)
    
                            else:
                                pass
    
    
                else:
                    print("网页访问失败")

    就这样,海量表情包快到碗里来。

    需要斗图的小伙伴自己动手试试吧~

  • 您还可以看一下 周声华老师的线性代数 精讲课程中的 行列式的性质小节, 巩固相关知识点