Python学习记录W05-06:内置模块详解之Random模块

import random

#随机整数:
print(random.randint(0,99))

#随机选取0到100间的偶数:
print(random.randrange(0,101,2))

#随机浮点数:
print(random.random())
print(random.uniform(1,10))

#随机字符:
print(random.choice('abcdefg&#%^*f'))

#多个字符中选取特定数量的字符:
print(random.sample('abcdefghij',3))  #['f','h','d']

#随机选取字符串:
print(random.choice(['apple','pear','peach','orange','lemon'])) #apple
#洗牌#
items = [1,2,3,4,5,6,7]
print(items)
random.shuffle(items)
print(items)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>音乐相册</title> <style> @import url("CSS/ring.css"); @import url("CSS/square.css"); /* 定义动画 */ @keyframes box-ani{ /* 开始动画 */ from{ transform: rotateX(-15deg) rotateY(10deg); } /* 结束动画 */ to{ transform: rotateX(-15deg) rotateY(370deg); } } /* 使用动画 */ .box{ animation-name: box-ani; animation-duration: 10s; animation-iteration-count: infinite; animation-timing-function: linear; } </style> </head> <body> <div class="btn-box"> <button class="btn">环形</button> <button class="btn-square">正方体</button> </div> <div class="box square"> <img src="img/w01.jpg" alt=""/> <img src="img/w02.jpg" alt=""/> <img src="img/w03.jpg" alt=""/> <img src="img/w04.jpg" alt=""/> <img src="img/w05.jpg" alt=""/> <img src="img/w06.jpg" alt=""/> <img src="img/w07.jpg" alt=""/> <img src="img/2014.jpg" alt=""/> <img src="img/2015.jpg" alt=""/> <img src="img/2016.jpg" alt=""/> <img src="img/2017.jpg" alt=""/> <img src="img/2018上.jpg" alt=""/> </div> </body> <script> var btn =document.querySelector(".btn"); var box =document.querySelector(".box"); var btnSquare=document.querySelector(".btn-square") btn.onclick =function(){ // 现在点击以后要在box的盒子上面添加一个class 为ring的样式 box.classList.remove("square"); box.classList.add("ring"); } btnSquare.onclick =function(){ box.classList.remove("ring"); box.classList.add("square"); } </script> </html>帮我写一个可以添加背景音乐的代码
06-09
可以在 body 标签中添加以下代码来实现添加背景音乐的功能: ```html <audio src="音乐文件的路径" autoplay loop></audio> ``` 其中,src 属性指定音乐文件的路径,autoplay 属性设为自动播放,loop 属性设为循环播放。例如,如果将音乐文件命名为 music.mp3,并放在项目的根目录下,可以将代码改为: ```html <audio src="music.mp3" autoplay loop></audio> ``` 将该代码添加到 body 标签的末尾即可。完整代码如下: ```html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>音乐相册</title> <style> @import url("CSS/ring.css"); @import url("CSS/square.css"); /* 定义动画 */ @keyframes box-ani{ /* 开始动画 */ from{ transform: rotateX(-15deg) rotateY(10deg); } /* 结束动画 */ to{ transform: rotateX(-15deg) rotateY(370deg); } } /* 使用动画 */ .box{ animation-name: box-ani; animation-duration: 10s; animation-iteration-count: infinite; animation-timing-function: linear; } </style> </head> <body> <audio src="music.mp3" autoplay loop></audio> <div class="btn-box"> <button class="btn">环形</button> <button class="btn-square">正方体</button> </div> <div class="box square"> <img src="img/w01.jpg" alt=""/> <img src="img/w02.jpg" alt=""/> <img src="img/w03.jpg" alt=""/> <img src="img/w04.jpg" alt=""/> <img src="img/w05.jpg" alt=""/> <img src="img/w06.jpg" alt=""/> <img src="img/w07.jpg" alt=""/> <img src="img/2014.jpg" alt=""/> <img src="img/2015.jpg" alt=""/> <img src="img/2016.jpg" alt=""/> <img src="img/2017.jpg" alt=""/> <img src="img/2018上.jpg" alt=""/> </div> <script> var btn =document.querySelector(".btn"); var box =document.querySelector(".box"); var btnSquare=document.querySelector(".btn-square") btn.onclick =function(){ // 现在点击以后要在box的盒子上面添加一个class 为ring的样式 box.classList.remove("square"); box.classList.add("ring"); } btnSquare.onclick =function(){ box.classList.remove("ring"); box.classList.add("square"); } </script> </body> </html> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值