按照题目要求编写的Python程序如下
import random
numlist=random.sample(range(0,10),5)
while numlist[0]==0:
numlist=random.sample(range(0,10),5)
num=int(''.join([str(i) for i in numlist]))
inputnum=int(input("输入号:"))
bonus=0
count=0
if inputnum==num:
bonus=10000
else:
for i in set(str(inputnum)):
if int(i) in numlist:
count+=1
bonus=1000*count
print("彩票号:%d" % num)
print("奖金:%d元" % bonus)
源代码(注意源代码的缩进)
新建一个单窗体的工程,在上面画出七个TEXTBOX,最好是一个控件数组,这样编程时容易控制,再建一个COMMOND BUTTON,将CAPTION改为“随机产生”。在程序运行后,每点击一下COMMAND1,将随机产生一组数字并按从小到大的顺序显示在文本框中。下面就是程序部分:Dim NumArray(1 To 7) As Integer′通用中定义Private Sub Command1_Click()
Dim i, j, N As Integer
For i = 1 To 7
NumArray(i) = 0
Next i
Randomize
NumArray(1) = Fix(1 + 32 * (Rnd()))
j = 1
Do
N = Fix(1 + 32 * (Rnd()))
For i = 1 To j
If N = NumArray(i) Then
Exit For ′重复时
ElseIf i = j Then ′未重复时
NumArray(i + 1) = N
j = j + 1
Exit For
End If
Next i
Loop While j <7
PopSort ′升序排列
For i = 1 To 7
Text1(i - 1).Text = NumArray(i)
Next i
End Sub
Private Sub PopSort() ′气泡排序法
Dim i, j, Temp As Integer
For i = 7 To 2 Step -1
For j = 7 - 1 To 1 Step -1
If i >= 7 - j + 1 Then
If NumArray(j + 1) <NumArray(j) Then
Temp = NumArray(j)
NumArray(j) = NumArray(j + 1)
NumArray(j + 1) = Temp
End If
End If
Next j
Next i
End Sub
祝册送宋rm比的 jjj.ee/rme7static void Main(string[] args)
{
string i = null
do
{
Console.Write("请输入整数(范围1~100)\n要退请输入0否则输入1")
i = Console.ReadLine()
if (i.Trim().Equals("0"))
{
return
}
} while (!i.Trim().Equals("1"))
start:
Random ra = new Random()
int rndInt = ra.Next(1, 100)
int input = 0
do
{
Console.Write("输入猜数值:")
i = Console.ReadLine()
if (!int.TryParse(i, out input))
{
continue
}
if (input >rndInt)
{
Console.Write("猜\n\n")
}
else if (input <rndInt)
{
Console.Write("猜\n\n")
}
} while (input != rndInt)
Console.Write("恭喜猜\n\n")
do
{
Console.Write("若继续猜测输入Y,若退则输入N!\n请输入:")
i = Console.ReadLine()
if (i.Trim().Equals("n", StringComparison.OrdinalIgnoreCase))
{
return
}
if (i.Trim().Equals("y", StringComparison.OrdinalIgnoreCase))
{
goto start
}
} while (!i.Trim().Equals("1"))
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)