简单“三行代码”教你打印金字塔

打印字母金字塔(python实现) 打印字母金字塔(python实现) 打印一个如图所示的金字塔: 思路: 整个过程分为两部分: 第一部分:分行打印(第一个,也就是最外层的for循环)。 第二部分:打印当前行,从左至右分为三段: 第一段:空格部分(代码中的第一个内层for循环) 第二段:倒序字母部分(代码中的第二个内层for循环) 第三段:正序字母部分(代码中的第三个内层for循环) ps:中间的 ’A‘ ,放在第二或第三段皆可,本文给出的代码将 ’A‘ 放在了第二段(代码中的第二个内层for循环) 代码如下: list 阅读详情

直接进入正题:

rows = int(input("请输入行数:")) # 输入金字塔行数

for i in range(1, rows+1):
    print(" "*(rows-i) + "*"*(2*i-1))

输出结果如下:

你学废了么

c语言 打印星号金字塔 打印*号金字塔 阅读详情

相关推荐

java实现打印金字塔

这是一道经典的例题,考验对for循环的掌握,具体要求为打印出如下金字塔: 分析每层打印出*的个数,找出其中的规律问题就变得简单了,需要一步一步来切勿急于求成: 具体代码实现如下: public class 空心金字塔练习 { public static void main (String[] args) { int i = 1; int j = 1; int k =1; //控制层数 for(i=1;i<=5;i++) { //控制每层的空格数 for(

weixin_53338688的博客 5516

C语言输出图形:宝塔形(三角形)字母。第一行A,第二行BB,第三行CCC……

C语言输出图形:宝塔形(三角形)字母。第一行A,第二行BB,第三行CCC…… 效果图: 代码部分: #include <stdio.h> void main() { int i=65,j,n; for(i=65;i<=68;i++) { for(n=1;n<=68-i;n++) printf(" "); for(j=1;j<=i-64;j++) printf("%c"

Deng7326的博客 6245

python打印字符金字塔_打印字母金字塔(python实现)

打印字母金字塔(python实现)打印字母金字塔(python实现)打印一个如图所示的金字塔:思路:整个过程分为两部分:第一部分:分行打印(第一个,也就是最外层的for循环)。第二部分:打印当前行,从左至右分为三段:第一段:空格部分(代码中的第一个内层for循环)第二段:倒序字母部分(代码中的第二个内层for循环)第三段:正序字母部分(代码中的第三个内层for循环)ps:中间的 ’A‘ ,放在第二...

weixin_39685762的博客 5762

打印金字塔

打印金字塔

xiaonan678的博客 2425

打印空心金字塔

输入任意整数,要求打印出"金字塔"。打印空心三角形,打印用户指定层数三角形,新手打怪之金字塔(多语言版)

m0_62172219的博客 2397

php练习——用for循环打印半金字塔、金字塔、正方形、倒金字塔、菱形、空心图形等

1、半金字塔 $n=5; //控制层数 for($i=1;$i //控制每层的 “*” 数 for($j=1;$j echo  "*"; } echo  ""; } 2、金字塔 $n=5; for($i=1;$i for($k=1;$k echo "&nbsp";   //输出空格 } for($j=1;$j echo "*"; } echo

Rxifan的专栏 4721

C语言程序设计:编写程序,打印以下图形(一个三行的倒金字塔)

编写程序,打印以下图形(一个三行的倒金字塔)

yjf1205的博客 889

C++编程题目打印金字塔和镂空金字塔

利用双重for循环打印金字塔和镂空金字塔

would20110710的博客 3115

【PL/SQL】用星号拼出金字塔

代码中首先声明了几个变量,然后使用嵌套循环去输出空格和星号,其中: 每层空格数=总层数-该层层数 每层星号数=当前层数*2-1 代码如下: declare v_number1 number(10); --外层循环控制金字塔层数 v_number2 number(10); --内层循环控制每行空格数 v_number3 number(10); --内层循环控制每行

Just Do IT 2338

华为昇腾 910B 实战:DeepSeek-R1 蒸馏模型高效部署与性能调优全解析

本文详细解析了在华为昇腾910B硬件平台上高效部署DeepSeek-R1蒸馏系列模型(14B/32B版本)的完整实战流程。内容涵盖从MindIE环境搭建、镜像获取、模型准备,到服务配置、内存参数调优、性能测试及常见问题排查,为开发者提供了基于昇腾910B进行大模型部署与优化的全链路指南。

weixin_28235513的博客 212

AI重塑运营商CRM:从传统办理到智能推荐的实战经验

本文探讨了AI技术如何重塑运营商CRM系统,从传统办理模式升级为智能推荐平台。文章首先分析了传统CRM系统在产品推荐效率、客户信息录入、业务流程和个性化服务等方面的痛点,提出AI赋能的解决方案。技术架构采用分层设计,包含智能推荐引擎、知识图谱系统和大模型集成三大核心模块。实战案例详细介绍了基于深度学习的智能推荐系统实现,包括用户行为特征提取、产品特征建模、推荐模型训练和实时推荐服务等关键组件代码实现,展示了AI如何提升运营商CRM系统的智能化水平和服务效率。

技术传感器的博客 1050

Python使用for循环打印金字塔

文章目录1. 正金字塔2. 倒金字塔3. 数字金字塔 1. 正金字塔 # 打印形状 # * *** ***** ******* ********* # 实现代码 # # 将金字塔看作一个由左边矩形、右边三角形组成的图形(拆分如下) # for i in range(a): # print('~'*(a - 1 - i) + '*'*(i + 1) + ' ' ...

林大夕可的博客 3万+

从RADIUS服务器到AP:实战搭建一个小型WPA2-Enterprise测试环境(FreeRADIUS + 家用路由器)

本文详细介绍了如何从零搭建WPA2-Enterprise测试环境,使用FreeRADIUS服务器和家用路由器实现企业级WiFi认证。通过实战指南,包括证书生成、EAP-PEAP配置、OpenWrt路由器设置及故障排查,帮助网络工程师和爱好者掌握802.1X协议栈的实际应用。

weixin_28715953的博客 326

在Java中打印金字塔图案

1、问题描述打印出金字塔图案,如图1所示。图12、问题分析这时一个很经典的循环应用的问题。我们都知道,打印输出的时候,都是从最左端输出,而这里第一个三角形符号是在最中间,这实际是因为三角形之前有很多空格。当我们使用圆圈来表示空格,实际的输出效果应该是图2的形式。图2分析图2,我们可以发现这个题目的奥秘。(1)  确定程序框架程序框架代码如下:publicclass Ch1_1{    public...

m0_37732829的博客 2万+

手把手教你用运放和基准源,把±10V信号变成ADC能吃的0-4V(附完整计算过程)

本文详细介绍了如何利用OP07运放和REF5040基准源设计工业级信号调理电路,将±10V传感器信号转换为0-4V ADC可接受范围。通过七步流程,包括需求分析、元器件选型、电路设计、理论计算、PCB布局、实测验证与性能优化,帮助工程师解决信号不匹配问题,提升系统精度与稳定性。

weixin_28731223的博客 468

使用R语言读取和处理CSV数据集

查看数据集的结构str(data)# 查看数据集的摘要统计信息str()函数将显示数据集的结构信息,包括变量名称、类型和前几行的值。summary()函数将提供数据集的摘要统计信息,如均值、中位数、最小值、最大值等。

CyberGenius的博客 3856

【ARM汇编】打印金字塔 | 打印倒三角

详细介绍:ARM 汇编中如何用循环语句打印金字塔和倒三角?

GRT609的博客 2268

OpenClaw进阶实战(二十三):微信公众号接入——被动回复、客服消息、素材管理

本文介绍了将OpenClaw接入微信公众号的完整方案,重点包含以下内容: 接入方案选型:对比官方插件、三方服务和自建中转三种方式,选择自建Node.js中转服务实现灵活控制 核心原理:通过中转服务器完成微信消息协议转换,处理5秒超时限制和异步回复机制 实战开发: 搭建Express中转服务 实现Token管理和消息处理 采用内存缓存对话历史 通过客服接口异步回复 官方插件方案:介绍2026年发布的ClawBot插件,支持文本/图片/文件收发 进阶功能:包括素材管理接口调用示例 该方案适用于需要深度定制公众号

PeterPan的博客 143

C语言打印下列的几种类型的金字塔

以上就是今天要讲的内容,本文仅仅简单介绍了利用C语言打印下列的几种类型的金字塔。

m0_65420451的博客 1万+

OpenCASCADE:Direct3D CSharp 示例

OpenCASCADE:Direct3D CSharp 示例OpenCASCADE:Direct3D CSharp 示例 OpenCASCADE:Direct3D CSharp 示例 此示例演示了如何在使用CSharp和Windows Presentation Foundation (WPF)编写的.Net应用程序中使用 OCCT 和 DirectX 库。 .Net、OCCT (C++) 和 DirectX 级别之间的连接由用 C++/CLI 编写的代理库OCCProxy和D3DProxy提供。代理库OCC

希望我的博客,能帮上你解决学习中工作中所遇到的问题 1828

Flink Web UI 如何使用和调试保姆级教程(持续更新)

Running Jobs(运行中的作业):显示正在运行的所有 Flink 作业的列表。每个作业都有一个独特的 Job ID,可以点击进入查看作业的详细信息。Completed Jobs(已完成的作业):显示已经完成或取消的作业列表。:显示当前集群中所有 TaskManager 的健康状态,包括 CPU 使用率、内存使用情况、Slot 数量等。Job Manager Configuration(JobManager 配置):显示 JobManager 的一些配置参数,帮助调试和优化 Flink 集群。

大模型大数据攻城狮的专栏 3993

C语言打印任意行数金字塔

目录循环训练使用for循环语句用 * 打印出n层金字塔打印空心金字塔打印一个棱形 循环训练 使用for循环语句用 * 打印出n层金字塔 #include<stdio.h> #define N 4 //N打印的层数 int main() { int i,j,k; //i是行 j是打印空格的数量 k是打印*的数量 for(i=1;i<=N;i++) { for(j=0;...

deroy 3067

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Python –如何打印金字塔

一个简单的Python示例,只打印一半和全部金字塔,只是为了好玩。 def half_pyramid(rows): print('Half pyramid...\n') for i in range(rows): print('*' * (i+1)) def full_pyramid(rows): print('\nFull pyramid...\n...

一名可爱的技术搬运工 5576

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

用java打印空白金字塔

打印一个空白金字塔 如图 代码如下: public class jinzita { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入需要打印的层数:"); int n=sc.nextInt(); int i,j,k;...

boxrq1的博客 8272

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

java简单打印金字塔

废话不多讲,直接暴力循环,去tm的性能优化。 例子: Scanner scanner = new Scanner(System.in); System.out.println("请输入金字塔的高度"); int h = scanner.nextInt(); //i 为当前打印高度 for(int i = 1;i<=h;i++)...

pannubi的博客 481

打印输出金字塔

java打印输出金字塔

qq_44485283的博客 3571
上一篇: 关于java工具包JDK逐帧保姆式安装与环境变量的配置
下一篇: 使用Xshell远程连接虚拟机失败的解决方法(之一)
澄绪猿
博客等级 码龄4年 1323粉丝 66原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值