p121: *题4.1:猜数字游戏.在程序中预设一个0~9之间的整数,让用户通过键盘输入所猜的数,如果大于预设的数,显示“遗憾,太大了!”:小于预设的数,显示“遗憾,太小了!”,如此循环,直至猜中该数,显示“预测N次,你猜中了!”,其中N是用户输入数字的次数. 源代码: from random import*y=5n=1m=Falsewhile(m==False): x=eval(input("请输入您猜想的数字:")) try: if(x>y):
#include<iostream> #include<string> using namespace std; int main() { string first_name; string last_name; char grade; int age; cout << "What is your first name? "; getline(cin,first_name); cout << endl << "Wha
4-1Python objects All Python objects have three attributes:type,ID,and value. All are readonly with a possible expection of the value(which can be changed only if the object is mutable). 4-5str()and repr() repr() is a built-in function while str() wa
5-8Geometry import math def sqcube(): s = float(raw_input('enter length of one side: ')) print 'the area is:', s ** 2., '(units squared)' print 'the volume is:', s ** 3., '(cubic units)'def cirsph(): r = float(raw_input('enter length of radius: ')) p
2-5 Loops and Numbers a) i = 0 while i <11: print i i += 1 b) for i in range(0,11): print i 2-6 Conditionals n =int( raw_input('enter a number:')) if n < 0: print 'negative' elif n > 0: print 'positive' else: print 'zero' 2-7 Loops and
#include <iostream> #include <cctype> using namespace std; int main() { char in_put; do { cout << "Please enter the letters (enter @ exit):"; cin >> in_put; if (islower(in_put)) cout << "The uppercase of the le
#include <iostream> using namespace std; int main() { ; cout << "Please enter two number: "; cin >> num_1; cin >> num_2; if (num_1 > num_2) { int a; a = num_1; num_1 = num_2; num_2 = a; } for (int i = num_1; i <= nu
#include<iostream> using namespace std; int main() { ; int shen_gao; cout <<"Please enter your leight in inches:____\b\b\b"; cin >> shen_gao; cout << "It is contains: " << shen_gao / unit << " f
#include<iostream> using namespace std; int main() { cout << "My name is Jiantong Chen." << endl << "I'm a student in the Xi'an University."; cin.get(); ; } #include<iostream> using namespace std; int main