0% found this document useful (0 votes)
18 views4 pages

3月18日

The document outlines basic programming constructs including variable declaration, input/output operations, conditional statements, loops, and functions. It provides examples of exercises such as checking if a number is positive or negative, comparing two numbers, printing multiplication tables, and creating patterns with nested loops. Additionally, it includes tasks for generating shapes like rectangles, pyramids, diamonds, and Pascal's triangle using loops.

Uploaded by

lidan88715
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

3月18日

The document outlines basic programming constructs including variable declaration, input/output operations, conditional statements, loops, and functions. It provides examples of exercises such as checking if a number is positive or negative, comparing two numbers, printing multiplication tables, and creating patterns with nested loops. Additionally, it includes tasks for generating shapes like rectangles, pyramids, diamonds, and Pascal's triangle using loops.

Uploaded by

lidan88715
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

基本的格式
BEGIN
INPUT x,y
sum  x+y
PRINT sum
END
2. 声明变量和赋值
DECLEAR num1, num2, result
INPUT num1, num2;
result  num1 + num2
PRINT num1, num2
3. If-else 选择的结构
IF grade >= 60 THEN
PRINT “Pass”
ELSE
PRINT “Fail”
ENDIF

4. 循环语句 for, while, repeat


FOR i FROM 1 TO 39 DO
PRINT “age”
ENDFOR

x0
WHILE x<10 DO
xx+1
PRINT x
ENDWHILE

REPEAT
INPUT num
UNTIL num <0

5. Function
FUNCTION Add(x, y)
RETURN x+y
ENDFUNCTION

PROCEDUCE PrintMessage( )
PRINT “Hello, World!”
ENDPROCEDUCE

CALL Add(x,y)
CALL PrintMessage( )
Exercise 1: Check if a Number is Positive or Negative
Task: Input a number and determine if it’s positive, negative, or zero.

INPUT number number = float (input (“Enter a number:


IF number > 0 THEN ”))
PRINT “this is a positive number” if number >0:
ELSE IF number <0 THEN print (“This is a positive number”)
elif number < 0:
PRINT “this is a negative number” print (“This is a negative number”)
ELSE else:
PRINT “this is zero” print (“This is zero”)
ENDIF
ENDIF

Exercise 4: Compare Two Numbers


Task: Input two numbers and determine which is larger, or if they are equal.
INPUT num1, num2
IF num1 > num2 THEN
OUTPUT”num1 is larger”
ELSE IF num1 < num2 THEN
OUTPUT “num2 is larger”
ELSE
OUTPUT “num1 and num2 are equal”
ENDIF
ENDIF

Practice 3: Print a Multiplication Table (e.g., 5 times table)


Task: Print the multiplication table for 5 (e.g., 5 x 1 = 5, up to 5 x 10 = 50).
5*1 = 5
5*2 = 10
5*3 = 15
……
5*10 = 50

FOR i FROM 1 TO 10 DO
for i in range (1,11):
OUTPUT “5*” i “=” 5*i print(f “5*{i} = {5*i}”)
NEWLINE
ENDFOR

SET i = 1 i =1
while i<=10 :
WHILE i <=10 DO
print(f “5*{i} = {5*i}”)
OUTPUT “5*” i “=” 5*i i +=1
NEWLINE
ii+1
ENDWHILE

SET i = 1
REPEAT
OUTPUT “5*” i “=” 5*i
NEWLINE
ii+1
UNTIL i>10

Practice 3: for 多次内循环语句


1.打印矩形星号图案:
使用嵌套的 for 循环,输出一个由星号(*)组成的 4 行 7 列的矩形。 *******
*******
*******
*******
for i in range (1,5):
for j in range (1,8):
print (“*”, end =””)
print ( )

2.打印金字塔形星号图案:
使用嵌套的 for 循环,输出一个金字塔形的星号图案,底部宽度为 7 个星号,高度为 4 行。
for i in range (1,5):
*
print(“ ”*(4-i), end = “”)
***
print(“*” * (2*i-1)) *****
*******
3. 打印菱形星号图案:
使用嵌套的 for 循环,输出一个菱形的星号图案,中心行宽度为 7 个星号,高度为 7 行。

*
*** for i in range (3, 0, -1):
***** print (“ ” *(4-i),
******* end=””)
***** print (“*” *(2*i-1))
***
*

1*1=1
1*2=2 2*2=4
4. 打印九九乘法表:
1*3=3 2*3=6 3*3=9
... 使用嵌套的 for 循环,输出标准的 9x9 乘法表。
1*9=9 2*9=18 ... for i in range (1, 10):
9*9=81 for j in range (1, i+1):
C: 1
print (i, "*” ,j, “=” ,i*j, end = “”)
Row: 1
print ()
5.打印帕斯卡三角形:
1
使用嵌套的 for 循环,输出帕斯卡三角形的前 5 行。 11
121
1331
14641

You might also like