一、关系运算符
二、逻辑运算符
三、条件语句
matlab:
%1
if conditional statement
command group
end
%2
if conditional statement
command group 1
else
command group 2
end
%3
if conditional statement 1
command group 1
elseif conditional statement 2
command group 2
...
elseif conditional statement #
command group #
...
else
command group n+1
end
#switch case
n = 1;
while (n ~= 0)
x = input ('Resistance: ');
switch x
case 100
disp (x)
case 200
disp (x)
case 300
disp (x)
case 400
disp (x)
otherwise
n = 0;
end
end
%例子
format bank
bill=input('Enter the amount of the bill (in dollars): ');
if (bill <= 10)
tip = 1.8;
elseif (bill > 10) && (bill <= 60)
tip = bill*0.18;
else
tip = bill*0.2;
end
disp('The tip is (in dollars):')
disp(tip)
python
#1
if conditional statement:
command group
#2
if conditional statement:
command group 1
else:
command group 2
#3
if conditional statement 1:
command group 1
elif conditional statement 2:
command group 2
...
elif conditional statement #:
command group #
...
else:
command group n+1
例子:
bill=int(input('Enter the amount of the bill (in dollars): '))
if (bill <= 10):
tip=1.8
elif (bill>10)and(bill<=60):
tip=bill*0.18
else:
tip=bill*0.2
print('The tip is (in dollars): %0.2f'% (tip))