python官网
https://www.python.org/
pycharm官网
https://www.jetbrains.com.cn/en-us/pycharm/
————————
python安装的时候,如果选择自主安装,一定要勾选这三项
如果安装完之后,cmd找不到python,说明没有设置环境变量
Python 的环境变量如何配置? - melody的回答 - 知乎
https://www.zhihu.com/question/562552205/answer/2959703739
c++ 输出一句话
#include<iostream>
using namespace std;
int main()
{
cout << "!!!" ;
return 0;
}
python 设置自动换行 如果不想换行,就在后面加一个【end=‘’】
print('hello world!')
print('hello world!',end='')
print('hello world!')
c++ 传参 (\n 换行)
#include<iostream>
using namespace std;
int main()
{
int a=2;
int b=3,c;
c=a+b;
cout << c;
cout << " ";
cout << "a+b的值是" << c << endl;
printf("a+b=\n");
printf("a+b=%d",c);
return 0;
}
python 传参,构建函数: 用‘.’连接 format()
age=20
name='L'
print('{0},{1}'.format(age,name))
print('{} age was {}'.format(name,age))
报错提示:
Traceback (most recent call last):
File "C:\Users\17424\Desktop\hello world.py", line 6, in <module>
name=L
NameError: name 'L' is not defined
报错原因:
name=‘’ 后面如果是文本或者字符串,需要用 英文格式下单引号引起来
直接把标签填进去,会引发报错;只能空格(前后数量一致的情况下彼此对应),或者从0开始编码 什么都不标,前后大括号和字符数量相同的情况下,正常识别
只标一个或者一两个,或者空格,报错
全标,正常
c++ for循环 从0打印到9
#include<iostream>
using namespace std;
int main()
{
for(int a=0;a<10;a=a+1)
{
printf("a=%d\n",a);
}return 0;
}
注意:return 0; 必须在for循环之外,否则打印 a=0
python for循环
从5开始打印,打印到(不大于)10
从0开始打印,打印不大于10
for i in range(5,10):
print("i=%d" %i , end=" ")
for i in range(0,10):
print("i=%d" %i)
for循环 打印10个数
for i in range(10):
print(i)
for y in range(10):
print(y,end=" ")
Python基础入门之range()函数用方法详解 - 信息科技云课堂的文章 - 知乎
https://zhuanlan.zhihu.com/p/610925345
一开始3只兔子,第一年后有6只兔子,第二年后有3*2*2只兔子,第n年?
#初始值是3只兔子
print("请输入兔子的数量:")
tu=int( input() )
print("请输入年份:") #打印提示的信息
n=int( input() ) #获取输入值
for i in range(0,n):
tu=tu*2 #每一年,兔子的数量都翻了一倍
print("%d年后,兔子的数量为%d" %(n,tu))
复习:c++ 输入、输出
#include<iostream>
using namespace std;
int main()
{
char name[10];
int age;
cout << "请输入名称和年龄";
cin >> name >> age;
cout << "您的名字为:" << name << ",年龄为:" << age << endl;
}
#include<string>
using namespace std;
int main(){
char name[10];
int age;
printf("请输入名字,年龄");
scanf("%s%d",&name,&age);
printf("您的名字为%s,年龄为%d",name,age);
}
解题:
#include<string>
using namespace std;
int main(){
int tu=3;
int year;
printf("请输入3只兔子繁衍了多少年");
scanf("%d",&year);
for(int i=0;i<year;i++){
tu=tu*2;
}
printf("%d年后,兔子的数量为%d",year,tu);
}
#include<string>
using namespace std;
int main(){
int tu;
int year;
printf("请输入多少只兔子,繁衍了多少年\n");
scanf("%d%d",&tu,&year);
for(int i=0;i<year;i++){
tu=tu*2;
}
printf("%d年后,兔子的数量为%d",year,tu);
}
注:for循环之后不要加 return 0; 否则没有输出结果